Skip to content

Commit

Permalink
Fix linting errors
Browse files Browse the repository at this point in the history
Signed-off-by: Sambhav Kothari <skothari44@bloomberg.net>
  • Loading branch information
sambhav committed Jun 28, 2021
1 parent 076d273 commit ccab05c
Show file tree
Hide file tree
Showing 12 changed files with 51 additions and 62 deletions.
20 changes: 10 additions & 10 deletions build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ test-key = "test-value"
err = buildpackTOML.Execute(&b, map[string]string{"APIVersion": "0.6"})
Expect(err).ToNot(HaveOccurred())

Expect(ioutil.WriteFile(filepath.Join(buildpackPath, "buildpack.toml"), b.Bytes(), 0644)).To(Succeed())
Expect(ioutil.WriteFile(filepath.Join(buildpackPath, "buildpack.toml"), b.Bytes(), 0600)).To(Succeed())

f, err := ioutil.TempFile("", "build-buildpackplan-path")
Expect(err).NotTo(HaveOccurred())
Expand All @@ -124,7 +124,7 @@ version = "test-version"
[entries.metadata]
test-key = "test-value"
`),
0644),
0600),
).To(Succeed())

commandPath = filepath.Join("bin", "build")
Expand All @@ -145,18 +145,18 @@ test-key = "test-value"
[metadata]
test-key = "test-value"
`),
0644),
0600),
).To(Succeed())

platformPath, err = ioutil.TempDir("", "build-platform-path")
Expect(err).NotTo(HaveOccurred())

Expect(os.MkdirAll(filepath.Join(platformPath, "bindings", "alpha"), 0755)).To(Succeed())
Expect(ioutil.WriteFile(filepath.Join(platformPath, "bindings", "alpha", "test-secret-key"),
[]byte("test-secret-value"), 0644)).To(Succeed())
[]byte("test-secret-value"), 0600)).To(Succeed())

Expect(os.MkdirAll(filepath.Join(platformPath, "env"), 0755)).To(Succeed())
Expect(ioutil.WriteFile(filepath.Join(platformPath, "env", "TEST_ENV"), []byte("test-value"), 0644)).
Expect(ioutil.WriteFile(filepath.Join(platformPath, "env", "TEST_ENV"), []byte("test-value"), 0600)).
To(Succeed())

tomlWriter = &mocks.TOMLWriter{}
Expand Down Expand Up @@ -192,7 +192,7 @@ id = "test-id"
name = "test-name"
version = "1.1.1"
`),
0644),
0600),
).To(Succeed())
})

Expand Down Expand Up @@ -404,7 +404,7 @@ version = "1.1.1"
err := buildpackTOML.Execute(&b, map[string]string{"APIVersion": "0.5"})
Expect(err).ToNot(HaveOccurred())

Expect(ioutil.WriteFile(filepath.Join(buildpackPath, "buildpack.toml"), b.Bytes(), 0644)).To(Succeed())
Expect(ioutil.WriteFile(filepath.Join(buildpackPath, "buildpack.toml"), b.Bytes(), 0600)).To(Succeed())

layer := libcnb.Layer{
Name: "test-name",
Expand Down Expand Up @@ -561,9 +561,9 @@ version = "1.1.1"
})

it("removes stale layers", func() {
Expect(ioutil.WriteFile(filepath.Join(layersPath, "alpha.toml"), []byte(""), 0644)).To(Succeed())
Expect(ioutil.WriteFile(filepath.Join(layersPath, "bravo.toml"), []byte(""), 0644)).To(Succeed())
Expect(ioutil.WriteFile(filepath.Join(layersPath, "store.toml"), []byte(""), 0644)).To(Succeed())
Expect(ioutil.WriteFile(filepath.Join(layersPath, "alpha.toml"), []byte(""), 0600)).To(Succeed())
Expect(ioutil.WriteFile(filepath.Join(layersPath, "bravo.toml"), []byte(""), 0600)).To(Succeed())
Expect(ioutil.WriteFile(filepath.Join(layersPath, "store.toml"), []byte(""), 0600)).To(Succeed())

layer := libcnb.Layer{Name: "alpha"}
layerContributor.On("Contribute", mock.Anything).Return(layer, nil)
Expand Down
8 changes: 4 additions & 4 deletions detect_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ mixins = ["test-name"]
[metadata]
test-key = "test-value"
`),
0644),
0600),
).To(Succeed())

f, err := ioutil.TempFile("", "detect-buildplan-path")
Expand All @@ -108,10 +108,10 @@ test-key = "test-value"

Expect(os.MkdirAll(filepath.Join(platformPath, "bindings", "alpha"), 0755)).To(Succeed())
Expect(ioutil.WriteFile(filepath.Join(platformPath, "bindings", "alpha", "test-secret-key"),
[]byte("test-secret-value"), 0644)).To(Succeed())
[]byte("test-secret-value"), 0600)).To(Succeed())

Expect(os.MkdirAll(filepath.Join(platformPath, "env"), 0755)).To(Succeed())
Expect(ioutil.WriteFile(filepath.Join(platformPath, "env", "TEST_ENV"), []byte("test-value"), 0644)).
Expect(ioutil.WriteFile(filepath.Join(platformPath, "env", "TEST_ENV"), []byte("test-value"), 0600)).
To(Succeed())

tomlWriter = &mocks.TOMLWriter{}
Expand Down Expand Up @@ -146,7 +146,7 @@ id = "test-id"
name = "test-name"
version = "1.1.1"
`),
0644),
0600),
).To(Succeed())
})

Expand Down
1 change: 0 additions & 1 deletion environment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,5 +140,4 @@ func testEnvironment(t *testing.T, context spec.G, it spec.S) {
filepath.Join("test-process", "TEST_NAME.prepend"): "test-value",
}))
})

}
2 changes: 0 additions & 2 deletions formatter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,5 @@ func testFormatter(t *testing.T, context spec.G, it spec.S) {

Expect(libcnb.PlatformFormatter(plat).String()).To(Equal("Platform contents: [. test-file]"))
})

})

}
6 changes: 3 additions & 3 deletions internal/config_map_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func testConfigMap(t *testing.T, context spec.G, it spec.S) {
})

it("loads the ConfigMap from a directory", func() {
Expect(ioutil.WriteFile(filepath.Join(path, "test-key"), []byte("test-value"), 0644)).To(Succeed())
Expect(ioutil.WriteFile(filepath.Join(path, "test-key"), []byte("test-value"), 0600)).To(Succeed())

cm, err := internal.NewConfigMapFromPath(path)
Expect(err).NotTo(HaveOccurred())
Expand All @@ -69,7 +69,7 @@ func testConfigMap(t *testing.T, context spec.G, it spec.S) {
Expect(ioutil.WriteFile(
filepath.Join(path, ".hidden", "test-key"),
[]byte("test-value"),
0644,
0600,
)).To(Succeed())
Expect(os.Symlink(
filepath.Join(".hidden", "test-key"),
Expand All @@ -82,7 +82,7 @@ func testConfigMap(t *testing.T, context spec.G, it spec.S) {
})

it("ignores hidden files", func() {
Expect(ioutil.WriteFile(filepath.Join(path, ".hidden-key"), []byte("hidden-value"), 0644)).To(Succeed())
Expect(ioutil.WriteFile(filepath.Join(path, ".hidden-key"), []byte("hidden-value"), 0600)).To(Succeed())

cm, err := internal.NewConfigMapFromPath(path)
Expect(err).NotTo(HaveOccurred())
Expand Down
1 change: 1 addition & 0 deletions internal/environment_writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ func (w EnvironmentWriter) Write(path string, environment map[string]string) err

for key, value := range environment {
f := filepath.Join(path, key)
// #nosec
if err := ioutil.WriteFile(f, []byte(value), 0644); err != nil {
return fmt.Errorf("unable to write file %s\n%w", f, err)
}
Expand Down
2 changes: 0 additions & 2 deletions internal/environment_writer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@ func testEnvironmentWriter(t *testing.T, context spec.G, it spec.S) {
path, err = ioutil.TempDir("", "environment-writer")
Expect(err).NotTo(HaveOccurred())
Expect(os.RemoveAll(path)).To(Succeed())

writer = internal.EnvironmentWriter{}
})

it.After(func() {
Expand Down
7 changes: 3 additions & 4 deletions layer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ func testLayer(t *testing.T, context spec.G, it spec.S) {
})

context("Layers", func() {

it.Before(func() {
var err error
path, err = ioutil.TempDir("", "layers")
Expand Down Expand Up @@ -121,7 +120,7 @@ build = false
[metadata]
test-key = "test-value"
`),
0644),
0600),
).To(Succeed())

l, err := layers.Layer("test-name")
Expand All @@ -143,7 +142,7 @@ build = false
[metadata]
test-key = "test-value"
`),
0644),
0600),
).To(Succeed())

l, err := layers.Layer("test-name")
Expand All @@ -166,7 +165,7 @@ cache = false
[metadata]
test-key = "test-value"
`),
0644),
0600),
).To(Succeed())

l, err := layers.Layer("test-name")
Expand Down
13 changes: 6 additions & 7 deletions main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ mixins = ["test-name"]
[metadata]
test-key = "test-value"
`),
0644),
0600),
).To(Succeed())

f, err := ioutil.TempFile("", "main-buildpackplan-path")
Expand All @@ -103,7 +103,7 @@ version = "test-version"
[entries.metadata]
test-key = "test-value"
`),
0644),
0600),
).To(Succeed())

f, err = ioutil.TempFile("", "main-buildplan-path")
Expand All @@ -129,7 +129,7 @@ test-key = "test-value"
[metadata]
test-key = "test-value"
`),
0644),
0600),
).To(Succeed())

platformPath, err = ioutil.TempDir("", "main-platform-path")
Expand All @@ -139,17 +139,17 @@ test-key = "test-value"
Expect(ioutil.WriteFile(
filepath.Join(platformPath, "bindings", "alpha", "metadata", "test-metadata-key"),
[]byte("test-metadata-value"),
0644,
0600,
)).To(Succeed())
Expect(os.MkdirAll(filepath.Join(platformPath, "bindings", "alpha", "secret"), 0755)).To(Succeed())
Expect(ioutil.WriteFile(
filepath.Join(platformPath, "bindings", "alpha", "secret", "test-secret-key"),
[]byte("test-secret-value"),
0644,
0600,
)).To(Succeed())

Expect(os.MkdirAll(filepath.Join(platformPath, "env"), 0755)).To(Succeed())
Expect(ioutil.WriteFile(filepath.Join(platformPath, "env", "TEST_ENV"), []byte("test-value"), 0644)).
Expect(ioutil.WriteFile(filepath.Join(platformPath, "env", "TEST_ENV"), []byte("test-value"), 0600)).
To(Succeed())

tomlWriter = &mocks.TOMLWriter{}
Expand Down Expand Up @@ -239,5 +239,4 @@ test-key = "test-value"

Expect(exitHandler.Calls[0].Arguments.Get(0)).To(MatchError("unsupported command test-command"))
})

}
9 changes: 4 additions & 5 deletions platform.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,10 @@ const (
// See the Service Binding Specification for Kubernetes for more details - https://k8s-service-bindings.github.io/spec/
EnvServiceBindings = "SERVICE_BINDING_ROOT"

// EnvCNBBindings is the name of the environment variable that contains the path to the CNB bindings directory. The CNB
// bindings spec will eventually by deprecated in favor of the Service Binding Specification for Kubernetes -
// https://github.com/buildpacks/rfcs/blob/main/text/0055-deprecate-service-bindings.md.
//
// EnvCNBBindings is the name of the environment variable that contains the path to the CNB bindings directory.
// See the CNB bindings extension spec for more details - https://github.com/buildpacks/spec/blob/main/extensions/bindings.md
// Deprecated: Use the Service Binding Specification for Kubernetes instead -
// https://github.com/buildpacks/rfcs/blob/main/text/0055-deprecate-service-bindings.md.
EnvCNBBindings = "CNB_BINDINGS"
)

Expand Down Expand Up @@ -115,7 +114,7 @@ func NewBindingFromPath(path string) (Binding, error) {

func (b Binding) String() string {
var s []string
for k, _ := range b.Secret {
for k := range b.Secret {
s = append(s, k)
}
sort.Strings(s)
Expand Down
40 changes: 18 additions & 22 deletions platform_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,25 +48,24 @@ func testPlatform(t *testing.T, context spec.G, it spec.S) {
})

context("CNB Bindings", func() {

it.Before(func() {
Expect(os.MkdirAll(filepath.Join(path, "alpha", "metadata"), 0755)).To(Succeed())
Expect(ioutil.WriteFile(filepath.Join(path, "alpha", "metadata", "kind"), []byte("test-kind"), 0644)).To(Succeed())
Expect(ioutil.WriteFile(filepath.Join(path, "alpha", "metadata", "provider"), []byte("test-provider"), 0644)).To(Succeed())
Expect(ioutil.WriteFile(filepath.Join(path, "alpha", "metadata", "test-metadata-key"), []byte("test-metadata-value"), 0644)).To(Succeed())
Expect(ioutil.WriteFile(filepath.Join(path, "alpha", "metadata", "test-metadata-key-trimmed"), []byte(" test-metadata-value-trimmed \n"), 0644)).To(Succeed())
Expect(ioutil.WriteFile(filepath.Join(path, "alpha", "metadata", "kind"), []byte("test-kind"), 0600)).To(Succeed())
Expect(ioutil.WriteFile(filepath.Join(path, "alpha", "metadata", "provider"), []byte("test-provider"), 0600)).To(Succeed())
Expect(ioutil.WriteFile(filepath.Join(path, "alpha", "metadata", "test-metadata-key"), []byte("test-metadata-value"), 0600)).To(Succeed())
Expect(ioutil.WriteFile(filepath.Join(path, "alpha", "metadata", "test-metadata-key-trimmed"), []byte(" test-metadata-value-trimmed \n"), 0600)).To(Succeed())
Expect(os.MkdirAll(filepath.Join(path, "alpha", "secret"), 0755)).To(Succeed())
Expect(ioutil.WriteFile(filepath.Join(path, "alpha", "secret", "test-secret-key"), []byte("test-secret-value"), 0644)).To(Succeed())
Expect(ioutil.WriteFile(filepath.Join(path, "alpha", "secret", "test-secret-key-trimmed"), []byte(" test-secret-value-trimmed \n"), 0644)).To(Succeed())
Expect(ioutil.WriteFile(filepath.Join(path, "alpha", "secret", "test-secret-key"), []byte("test-secret-value"), 0600)).To(Succeed())
Expect(ioutil.WriteFile(filepath.Join(path, "alpha", "secret", "test-secret-key-trimmed"), []byte(" test-secret-value-trimmed \n"), 0600)).To(Succeed())

Expect(os.MkdirAll(filepath.Join(path, "bravo", "metadata"), 0755)).To(Succeed())
Expect(ioutil.WriteFile(filepath.Join(path, "bravo", "metadata", "kind"), []byte("test-kind"), 0644)).To(Succeed())
Expect(ioutil.WriteFile(filepath.Join(path, "bravo", "metadata", "provider"), []byte("test-provider"), 0644)).To(Succeed())
Expect(ioutil.WriteFile(filepath.Join(path, "bravo", "metadata", "test-metadata-key"), []byte("test-metadata-value"), 0644)).To(Succeed())
Expect(ioutil.WriteFile(filepath.Join(path, "bravo", "metadata", "test-metadata-key-trimmed"), []byte(" test-metadata-value-trimmed \n"), 0644)).To(Succeed())
Expect(ioutil.WriteFile(filepath.Join(path, "bravo", "metadata", "kind"), []byte("test-kind"), 0600)).To(Succeed())
Expect(ioutil.WriteFile(filepath.Join(path, "bravo", "metadata", "provider"), []byte("test-provider"), 0600)).To(Succeed())
Expect(ioutil.WriteFile(filepath.Join(path, "bravo", "metadata", "test-metadata-key"), []byte("test-metadata-value"), 0600)).To(Succeed())
Expect(ioutil.WriteFile(filepath.Join(path, "bravo", "metadata", "test-metadata-key-trimmed"), []byte(" test-metadata-value-trimmed \n"), 0600)).To(Succeed())
Expect(os.MkdirAll(filepath.Join(path, "bravo", "secret"), 0755)).To(Succeed())
Expect(ioutil.WriteFile(filepath.Join(path, "bravo", "secret", "test-secret-key"), []byte("test-secret-value"), 0644)).To(Succeed())
Expect(ioutil.WriteFile(filepath.Join(path, "bravo", "secret", "test-secret-key-trimmed"), []byte(" test-secret-value-trimmed \n"), 0644)).To(Succeed())
Expect(ioutil.WriteFile(filepath.Join(path, "bravo", "secret", "test-secret-key"), []byte("test-secret-value"), 0600)).To(Succeed())
Expect(ioutil.WriteFile(filepath.Join(path, "bravo", "secret", "test-secret-key-trimmed"), []byte(" test-secret-value-trimmed \n"), 0600)).To(Succeed())
})

context("Binding", func() {
Expand Down Expand Up @@ -196,17 +195,16 @@ func testPlatform(t *testing.T, context spec.G, it spec.S) {
})

context("Kubernetes Service Bindings", func() {

it.Before(func() {
Expect(os.MkdirAll(filepath.Join(path, "alpha"), 0755)).To(Succeed())
Expect(ioutil.WriteFile(filepath.Join(path, "alpha", "type"), []byte("test-type"), 0644)).To(Succeed())
Expect(ioutil.WriteFile(filepath.Join(path, "alpha", "provider"), []byte("test-provider"), 0644)).To(Succeed())
Expect(ioutil.WriteFile(filepath.Join(path, "alpha", "test-secret-key"), []byte("test-secret-value"), 0644)).To(Succeed())
Expect(ioutil.WriteFile(filepath.Join(path, "alpha", "type"), []byte("test-type"), 0600)).To(Succeed())
Expect(ioutil.WriteFile(filepath.Join(path, "alpha", "provider"), []byte("test-provider"), 0600)).To(Succeed())
Expect(ioutil.WriteFile(filepath.Join(path, "alpha", "test-secret-key"), []byte("test-secret-value"), 0600)).To(Succeed())

Expect(os.MkdirAll(filepath.Join(path, "bravo"), 0755)).To(Succeed())
Expect(ioutil.WriteFile(filepath.Join(path, "bravo", "type"), []byte("test-type"), 0644)).To(Succeed())
Expect(ioutil.WriteFile(filepath.Join(path, "bravo", "provider"), []byte("test-provider"), 0644)).To(Succeed())
Expect(ioutil.WriteFile(filepath.Join(path, "bravo", "test-secret-key"), []byte("test-secret-value"), 0644)).To(Succeed())
Expect(ioutil.WriteFile(filepath.Join(path, "bravo", "type"), []byte("test-type"), 0600)).To(Succeed())
Expect(ioutil.WriteFile(filepath.Join(path, "bravo", "provider"), []byte("test-provider"), 0600)).To(Succeed())
Expect(ioutil.WriteFile(filepath.Join(path, "bravo", "test-secret-key"), []byte("test-secret-value"), 0600)).To(Succeed())
})

context("Binding", func() {
Expand Down Expand Up @@ -393,9 +391,7 @@ func testPlatform(t *testing.T, context spec.G, it spec.S) {
Expect(libcnb.NewBindingsForBuild("does-not-exist")).To(Equal(libcnb.Bindings{}))
})
})

})
})
})

}
4 changes: 2 additions & 2 deletions poet/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,15 +126,15 @@ func (Logger) print(writer io.Writer, a ...interface{}) {
s := fmt.Sprint(a...)

if !strings.HasSuffix(s, "\n") {
s = s + "\n"
s += "\n"
}

_, _ = fmt.Fprint(writer, s)
}

func (Logger) printf(writer io.Writer, format string, a ...interface{}) {
if !strings.HasSuffix(format, "\n") {
format = format + "\n"
format += "\n"
}

_, _ = fmt.Fprintf(writer, format, a...)
Expand Down

0 comments on commit ccab05c

Please sign in to comment.