aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--config.go35
-rw-r--r--config_test.go19
2 files changed, 4 insertions, 50 deletions
diff --git a/config.go b/config.go
index 2588f39..d562154 100644
--- a/config.go
+++ b/config.go
@@ -1,16 +1,16 @@
package main
import (
- "fmt"
"os"
- "sort"
"strings"
yaml "gopkg.in/yaml.v2"
)
-const _defaultGodocServer = "pkg.go.dev"
-const _defaultBranch = "master"
+const (
+ _defaultGodocServer = "pkg.go.dev"
+ _defaultBranch = "master"
+)
// Config represents the structure of the yaml file
type Config struct {
@@ -28,29 +28,6 @@ type Package struct {
URL string `yaml:"url"`
}
-// ensureAlphabetical checks that the packages are listed alphabetically in the configuration.
-func ensureAlphabetical(data []byte) bool {
- // A yaml.MapSlice perservers ordering of keys: https://pkg.go.dev/gopkg.in/yaml.v2#MapSlice
- var c struct {
- Packages yaml.MapSlice `yaml:"packages"`
- }
-
- if err := yaml.Unmarshal(data, &c); err != nil {
- return false
- }
-
- packageNames := make([]string, 0, len(c.Packages))
- for _, v := range c.Packages {
- name, ok := v.Key.(string)
- if !ok {
- return false
- }
- packageNames = append(packageNames, name)
- }
-
- return sort.StringsAreSorted(packageNames)
-}
-
// Parse takes a path to a yaml file and produces a parsed Config
func Parse(path string) (*Config, error) {
var c Config
@@ -64,10 +41,6 @@ func Parse(path string) (*Config, error) {
return nil, err
}
- if !ensureAlphabetical(data) {
- return nil, fmt.Errorf("packages in %s must be alphabetically ordered", path)
- }
-
if c.Godoc.Host == "" {
c.Godoc.Host = _defaultGodocServer
} else {
diff --git a/config_test.go b/config_test.go
index eb6c463..e4146b1 100644
--- a/config_test.go
+++ b/config_test.go
@@ -106,22 +106,3 @@ packages:
})
}
}
-
-func TestNotAlphabetical(t *testing.T) {
- path, clean := TempFile(t, `
-
-url: google.golang.org
-packages:
- grpc:
- repo: github.com/grpc/grpc-go
- atomic:
- repo: github.com/uber-go/atomic
-
-`)
- defer clean()
-
- _, err := Parse(path)
- if assert.Error(t, err, "YAML configuration is not listed alphabetically") {
- assert.Contains(t, err.Error(), "must be alphabetically ordered")
- }
-}