Skip to content

Commit

Permalink
Merge branch 'standarize-tests' of github.com:dikhan/terraform-provid…
Browse files Browse the repository at this point in the history
…er-openapi into standarize-tests
  • Loading branch information
lillchan committed Jul 18, 2020
2 parents 0d9961b + 6988bd3 commit 12da6e9
Show file tree
Hide file tree
Showing 13 changed files with 570 additions and 826 deletions.
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,14 @@ require (
github.com/spf13/cobra v0.0.3
github.com/stretchr/testify v1.3.0
github.com/stvp/go-udp-testing v0.0.0-20191102171040-06b61409b154
github.com/yuin/goldmark v1.1.33 // indirect
github.com/zach-klippenstein/goregen v0.0.0-20160303162051-795b5e3961ea // indirect
golang.org/x/crypto v0.0.0-20200709230013-948cd5f35899 // indirect
golang.org/x/lint v0.0.0-20200302205851-738671d3881b // indirect
golang.org/x/net v0.0.0-20200707034311-ab3426394381 // indirect
golang.org/x/sys v0.0.0-20200625212154-ddb9806d33ae // indirect
golang.org/x/text v0.3.3 // indirect
golang.org/x/tools v0.0.0-20200709181711-e327e1019dfe // indirect
golang.org/x/tools v0.0.0-20200717024301-6ddee64345a6 // indirect
gopkg.in/mgo.v2 v2.0.0-20160818020120-3f83fa500528 // indirect
gopkg.in/yaml.v2 v2.2.2
)
Expand Down
3 changes: 3 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,7 @@ github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9de
github.com/yuin/goldmark v1.1.30/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.1.31/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.1.33/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/zach-klippenstein/goregen v0.0.0-20160303162051-795b5e3961ea h1:CyhwejzVGvZ3Q2PSbQ4NRRYn+ZWv5eS1vlaEusT+bAI=
github.com/zach-klippenstein/goregen v0.0.0-20160303162051-795b5e3961ea/go.mod h1:eNr558nEUjP8acGw8FFjTeWvSgU1stO7FAO6eknhHe4=
github.com/zclconf/go-cty v1.0.0 h1:EWtv3gKe2wPLIB9hQRQJa7k/059oIfAqcEkCNnaVckk=
Expand Down Expand Up @@ -457,6 +458,8 @@ golang.org/x/tools v0.0.0-20200701151220-7cb253f4c4f8 h1:6MeBvT5neYXu4OAaLRGMO5T
golang.org/x/tools v0.0.0-20200701151220-7cb253f4c4f8/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE=
golang.org/x/tools v0.0.0-20200709181711-e327e1019dfe h1:BT/vSbkiKG3rURL2PMNvsoVnPUqYiSv4HYQL/gVKAZw=
golang.org/x/tools v0.0.0-20200709181711-e327e1019dfe/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA=
golang.org/x/tools v0.0.0-20200717024301-6ddee64345a6 h1:nULzSsKgihxFGLnQFv2T7lE5vIhOtg8ZPpJHapEt7o0=
golang.org/x/tools v0.0.0-20200717024301-6ddee64345a6/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
Expand Down
35 changes: 7 additions & 28 deletions openapi/plugin_config_schema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,8 @@ func TestNewPluginConfigSchemaV1(t *testing.T) {
}
Convey("When NewPluginConfigSchemaV1 method is called", func() {
pluginConfigSchemaV1 := NewPluginConfigSchemaV1(services)
Convey("And the pluginConfigSchema returned should implement PluginConfigSchema interface", func() {
Convey("And the pluginConfigSchema returned should implement PluginConfigSchema interface and have services configured", func() {
var _ PluginConfigSchema = pluginConfigSchemaV1
})
Convey("And the pluginConfigSchema services", func() {
So(pluginConfigSchemaV1.Services, ShouldNotBeNil)
})
})
Expand Down Expand Up @@ -74,9 +72,6 @@ func TestPluginConfigSchemaV1Validate(t *testing.T) {
}
Convey("When Validate method is called", func() {
err := pluginConfigSchema.Validate()
Convey("Then the error returned should NOT be nil as version is not supported", func() {
So(err, ShouldNotBeNil)
})
Convey("And the error returned be equal to", func() {
So(err.Error(), ShouldEqual, "provider configuration version not matching current implementation, please use version '1' of provider configuration specification")
})
Expand All @@ -97,13 +92,9 @@ func TestPluginConfigSchemaV1GetServiceConfig(t *testing.T) {
pluginConfigSchema = NewPluginConfigSchemaV1(services)
Convey("When GetServiceConfig method is called with a service described in the configuration", func() {
serviceConfig, err := pluginConfigSchema.GetServiceConfig("test")
Convey("Then the error returned should be nil as configuration is correct", func() {
Convey("Then serviceConfig should not be nil, the url returned should be equal to the one in the service configuration and the error returned should be nil as configuration is correct", func() {
So(err, ShouldBeNil)
})
Convey("And the serviceConfig should not be nil", func() {
So(serviceConfig, ShouldNotBeNil)
})
Convey("And the url returned should be equal to the one in the service configuration", func() {
So(serviceConfig.GetSwaggerURL(), ShouldEqual, expectedURL)
})
})
Expand All @@ -129,10 +120,8 @@ func TestPluginConfigSchemaV1GetVersion(t *testing.T) {
pluginConfigSchema = NewPluginConfigSchemaV1(services)
Convey("When GetVersion method is called", func() {
configVersion, err := pluginConfigSchema.GetVersion()
Convey("Then the error returned should be nil as configuration is correct", func() {
Convey("Then the serviceConfig should not be nil and error returned should be nil as configuration is correct", func() {
So(err, ShouldBeNil)
})
Convey("And the serviceConfig should not be nil", func() {
So(configVersion, ShouldEqual, "1")
})
})
Expand All @@ -153,13 +142,9 @@ func TestPluginConfigSchemaV1GetAllServiceConfigurations(t *testing.T) {
pluginConfigSchema = NewPluginConfigSchemaV1(services)
Convey("When GetAllServiceConfigurations method is called", func() {
serviceConfigurations, err := pluginConfigSchema.GetAllServiceConfigurations()
Convey("Then the error returned should be nil as configuration is correct", func() {
Convey("Then the serviceConfigurations contain 1 configuration, serviceConfigurations item should be test and error returned should be nil as configuration is correct", func() {
So(err, ShouldBeNil)
})
Convey("And the serviceConfigurations contain 1 configuration", func() {
So(len(serviceConfigurations), ShouldEqual, 1)
})
Convey("And the serviceConfigurations item should be test", func() {
So(serviceConfigurations[serviceConfigName], ShouldNotBeNil)
})
})
Expand Down Expand Up @@ -207,10 +192,8 @@ func TestPluginConfigSchemaV1Marshal(t *testing.T) {
pluginConfigSchema = NewPluginConfigSchemaV1(services)
Convey("When Marshal method is called", func() {
marshalConfig, err := pluginConfigSchema.Marshal()
Convey("Then the error returned should be nil as configuration is correct", func() {
Convey("Then the marshalConfig should contain the right marshal configuration and the error returned should be nil as configuration is correct", func() {
So(err, ShouldBeNil)
})
Convey("And the marshalConfig should contain the right marshal configuration", func() {
expectedConfig := fmt.Sprintf(`version: "1"
services:
test:
Expand Down Expand Up @@ -268,10 +251,8 @@ services:
pluginConfigSchema = NewPluginConfigSchemaV1(services)
Convey("When Marshal method is called", func() {
marshalConfig, err := pluginConfigSchema.Marshal()
Convey("Then the error returned should be nil as configuration is correct", func() {
Convey("Then the marshalConfig should contain the right marshal configuration (and the plugin_version property should not be present) and the error returned should be nil as configuration is correct", func() {
So(err, ShouldBeNil)
})
Convey("And the marshalConfig should contain the right marshal configuration (and the plugin_version property should not be present)", func() {
expectedConfig := fmt.Sprintf(`version: "1"
services:
test:
Expand Down Expand Up @@ -312,10 +293,8 @@ services:
pluginConfigSchema = NewPluginConfigSchemaV1(services)
Convey("When Marshal method is called", func() {
marshalConfig, err := pluginConfigSchema.Marshal()
Convey("Then the error returned should be nil as configuration is correct", func() {
Convey("Then the marshalConfig should contain the right marshal configuration (and the plugin_version property should not be present) and the error returned should be nil as configuration is correct", func() {
So(err, ShouldBeNil)
})
Convey("And the marshalConfig should contain the right marshal configuration (and the plugin_version property should not be present)", func() {
expectedConfig := fmt.Sprintf(`version: "1"
services:
test:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,6 @@ func TestServiceSchemaConfigurationV1ExecuteCommand(t *testing.T) {
}
Convey("When ExecuteCommand method is called", func() {
err := serviceSchemaConfigurationV1.ExecuteCommand()
Convey("And the err returned should NOT be nil", func() {
So(err, ShouldNotBeNil)
})
Convey("And the err message returned should be the expected", func() {
So(err.Error(), ShouldEqual, "provider schema property 'some_property_name' command failed: command '[cat nonexistingfile]' failed: cat: nonexistingfile: No such file or directory\n(exit status 1)")
})
Expand All @@ -66,9 +63,6 @@ func TestServiceSchemaConfigurationV1ExecuteCommand(t *testing.T) {
}
Convey("When ExecuteCommand method is called", func() {
err := serviceSchemaConfigurationV1.ExecuteCommand()
Convey("And the err returned should NOT be nil", func() {
So(err, ShouldNotBeNil)
})
Convey("And the err message returned should be the expected", func() {
So(err.Error(), ShouldEqual, "provider schema property 'some_property_name' command failed: command '[sleep 2]' did not finish executing within the expected time 1s (signal: killed)")
})
Expand Down Expand Up @@ -100,9 +94,6 @@ func TestServiceSchemaConfigurationV1Exec(t *testing.T) {
Convey("When exec method is called", func() {
go serviceSchemaConfigurationV1.exec(doneChan)
err := <-doneChan
Convey("And the err returned should NOT be nil", func() {
So(err, ShouldNotBeNil)
})
Convey("And the err message returned should be the expected", func() {
So(err.Error(), ShouldEqual, "command '[cat nonexistingfile]' failed: cat: nonexistingfile: No such file or directory\n(exit status 1)")
})
Expand All @@ -118,9 +109,6 @@ func TestServiceSchemaConfigurationV1Exec(t *testing.T) {
Convey("When exec method is called", func() {
go serviceSchemaConfigurationV1.exec(doneChan)
err := <-doneChan
Convey("And the err returned should NOT be nil", func() {
So(err, ShouldNotBeNil)
})
Convey("And the err message returned should be the expected", func() {
So(err.Error(), ShouldEqual, "command '[sleep 2]' did not finish executing within the expected time 1s (signal: killed)")
})
Expand All @@ -136,10 +124,8 @@ func TestServiceSchemaConfigurationV1GetDefaultValue(t *testing.T) {
}
Convey("When GetDefaultValue method is called", func() {
value, err := serviceSchemaConfigurationV1.GetDefaultValue()
Convey("And the err returned should be nil", func() {
Convey("Then the value returned should matched the default one and the err returned should be nil", func() {
So(err, ShouldBeNil)
})
Convey("And the value returned should matched the default one", func() {
So(value, ShouldEqual, serviceSchemaConfigurationV1.DefaultValue)
})
})
Expand All @@ -160,10 +146,8 @@ func TestServiceSchemaConfigurationV1GetDefaultValue(t *testing.T) {
}
Convey("When GetDefaultValue method is called", func() {
value, err := serviceSchemaConfigurationV1.GetDefaultValue()
Convey("And the err returned should be nil", func() {
Convey("Then the value returned should matched the default one and the err returned should be nil", func() {
So(err, ShouldBeNil)
})
Convey("And the value returned should matched the default one", func() {
So(value, ShouldEqual, expectedValue)
})
})
Expand All @@ -186,10 +170,8 @@ func TestServiceSchemaConfigurationV1GetDefaultValue(t *testing.T) {
}
Convey("When GetDefaultValue method is called", func() {
value, err := serviceSchemaConfigurationV1.GetDefaultValue()
Convey("And the err returned should be nil", func() {
Convey("Then the value returned should matched the default one and the err returned should be nil", func() {
So(err, ShouldBeNil)
})
Convey("And the value returned should matched the default one", func() {
So(value, ShouldEqual, expectedValue)
})
})
Expand All @@ -210,9 +192,6 @@ func TestServiceSchemaConfigurationV1GetDefaultValue(t *testing.T) {
}
Convey("When GetDefaultValue method is called", func() {
_, err := serviceSchemaConfigurationV1.GetDefaultValue()
Convey("And the err returned should NOT be nil", func() {
So(err, ShouldNotBeNil)
})
Convey("And the err message should be", func() {
So(err.Error(), ShouldContainSubstring, "'schemaPropertyName': 'nonSupported' content type not supported")
})
Expand All @@ -230,9 +209,6 @@ func TestServiceSchemaConfigurationV1GetDefaultValue(t *testing.T) {
}
Convey("When GetDefaultValue method is called", func() {
_, err := serviceSchemaConfigurationV1.GetDefaultValue()
Convey("And the err returned should NOT be nil", func() {
So(err, ShouldNotBeNil)
})
Convey("And the err message should be", func() {
So(err.Error(), ShouldContainSubstring, "failed to read external configuration file 'som_non_existing_file' for schema property 'schemaPropertyName': open som_non_existing_file: no such file or directory")
})
Expand All @@ -256,9 +232,6 @@ func TestServiceSchemaConfigurationV1GetDefaultValue(t *testing.T) {
}
Convey("When GetDefaultValue method is called", func() {
_, err := serviceSchemaConfigurationV1.GetDefaultValue()
Convey("And the err returned should NOT be nil", func() {
So(err, ShouldNotBeNil)
})
Convey("And the err message should be", func() {
So(err.Error(), ShouldContainSubstring, "key error: wrong not found in object")
})
Expand All @@ -279,13 +252,9 @@ func TestServiceExternalConfigurationV1GetFileParser(t *testing.T) {
}
Convey("When getFileParser method is called with some content", func() {
parser, err := serviceExternalConfigurationV1.getFileParser()
Convey("Then the error returned should be nil", func() {
Convey("Then parser returned should be of type parserRaw and parser get value should return the right value and the error returned should be nil", func() {
So(err, ShouldBeNil)
})
Convey("And the parser returned should be of type parserRaw", func() {
So(parser, ShouldHaveSameTypeAs, parserRaw{})
})
Convey("And the parser get value should return the right value", func() {
value, err := parser.getValue()
So(err, ShouldBeNil)
So(value, ShouldEqual, expectedValue)
Expand All @@ -306,13 +275,9 @@ func TestServiceExternalConfigurationV1GetFileParser(t *testing.T) {
}
Convey("When getFileParser method is called with some content", func() {
parser, err := serviceExternalConfigurationV1.getFileParser()
Convey("Then the error returned should be nil", func() {
Convey("Then the parser returned should be of type parserRaw and the parser get value should return the right value and the error returned should be nil", func() {
So(err, ShouldBeNil)
})
Convey("And the parser returned should be of type parserRaw", func() {
So(parser, ShouldHaveSameTypeAs, parserJSON{})
})
Convey("And the parser get value should return the right value", func() {
value, err := parser.getValue()
So(err, ShouldBeNil)
So(value, ShouldEqual, expectedValue)
Expand All @@ -332,9 +297,6 @@ func TestServiceExternalConfigurationV1GetFileParser(t *testing.T) {
}
Convey("When getFileParser method is called with some content", func() {
_, err := serviceExternalConfigurationV1.getFileParser()
Convey("Then the error returned should be nil", func() {
So(err, ShouldNotBeNil)
})
Convey("And the err message should be", func() {
So(err.Error(), ShouldContainSubstring, "'nonSupported' content type not supported")
})
Expand Down Expand Up @@ -364,10 +326,8 @@ func TestSchemaFileParserRawGetValue(t *testing.T) {
}
Convey("When getValue method is called", func() {
value, err := parserRaw.getValue()
Convey("Then the error returned should be nil", func() {
Convey("Then value returned should match the expected content and the error returned should be nil", func() {
So(err, ShouldBeNil)
})
Convey("And the value returned should match the content", func() {
So(value, ShouldEqual, expectedContent)
})
})
Expand Down Expand Up @@ -401,12 +361,13 @@ func TestSchemaFileParserJsonGetValue(t *testing.T) {
}
Convey("When getValue method is called", func() {
value, err := parserJSON.getValue()
Convey("Then the error returned should be nil", func() {
Convey("Then the value returned should match the content expected and the error returned should be nil", func() {
So(err, ShouldBeNil)
})
Convey("And the value returned should match the content", func() {
So(value, ShouldEqual, expectedValue)
})
Convey("And ", func() {

})
})
})

Expand All @@ -420,9 +381,6 @@ func TestSchemaFileParserJsonGetValue(t *testing.T) {
}
Convey("When getValue method is called", func() {
_, err := parserJSON.getValue()
Convey("Then the error returned should NOT be nil", func() {
So(err, ShouldNotBeNil)
})
Convey("And the error returned should be", func() {
So(err.Error(), ShouldEqual, "key error: someNonExistingKey not found in object")
})
Expand Down
4 changes: 1 addition & 3 deletions openapi/plugin_config_services_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,8 @@ func TestNewServiceConfigV1(t *testing.T) {
insecureSkipVerifyEnabled := true
Convey("When NewServiceConfigV1 method is called", func() {
pluginConfigSchemaV1 := NewServiceConfigV1(url, insecureSkipVerifyEnabled, &TelemetryConfig{})
Convey("And the pluginConfigSchema returned should implement PluginConfigSchema interface", func() {
Convey("And the pluginConfigSchema returned should implement PluginConfigSchema interface and pluginConfigSchema should contain the configured telemetry", func() {
var _ ServiceConfiguration = pluginConfigSchemaV1
})
Convey("And the pluginConfigSchema should contain the configured telemetry", func() {
So(pluginConfigSchemaV1.TelemetryConfig, ShouldNotBeNil)
})
})
Expand Down
Loading

0 comments on commit 12da6e9

Please sign in to comment.