Skip to content

Commit

Permalink
fix: add godoc comment to generated embed.FS
Browse files Browse the repository at this point in the history
This adds a godoc comment to the generated embed.go which embeds the
compiled OpenAPI specs for compilation into a Go service.

Added a test to assert that the godoc comment does not interfere with
the //go:embed magic comments.

Fixes #120.
  • Loading branch information
cmars committed Jan 14, 2022
1 parent 25fb58e commit c0fec12
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 0 deletions.
1 change: 1 addition & 0 deletions internal/compiler/compiler.go
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,7 @@ import "embed"
{{ range .VersionSpecFiles -}}
//go:embed {{ . }}
{{ end -}}
// Versions contains OpenAPI specs for each distinct release version.
var Versions embed.FS
`))

Expand Down
29 changes: 29 additions & 0 deletions versionware/example/embed_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package example

import (
"testing"

qt "github.com/frankban/quicktest"

"github.com/snyk/vervet"
"github.com/snyk/vervet/versionware/example/releases"
)

func TestEmbedding(t *testing.T) {
c := qt.New(t)

specs, err := vervet.LoadVersions(releases.Versions)
c.Assert(err, qt.IsNil)
c.Assert(specs, qt.HasLen, 3)
var versions []string
for i := range specs {
version, err := vervet.ExtensionString(specs[i].ExtensionProps, vervet.ExtSnykApiVersion)
c.Assert(err, qt.IsNil)
versions = append(versions, version)
}
c.Assert(versions, qt.ContentEquals, []string{
"2021-11-01~experimental",
"2021-11-08~experimental",
"2021-11-20~experimental",
})
}
1 change: 1 addition & 0 deletions versionware/example/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module github.com/snyk/vervet/versionware/example
go 1.16

require (
github.com/frankban/quicktest v1.13.0 // indirect
github.com/getkin/kin-openapi v0.87.0
github.com/go-chi/chi/v5 v5.0.7
github.com/gorilla/mux v1.8.0
Expand Down
1 change: 1 addition & 0 deletions versionware/example/releases/embed.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ import "embed"
//go:embed 2021-11-08~experimental/spec.yaml
//go:embed 2021-11-20~experimental/spec.json
//go:embed 2021-11-20~experimental/spec.yaml
// Versions contains OpenAPI specs for each distinct release version.
var Versions embed.FS

0 comments on commit c0fec12

Please sign in to comment.