Skip to content

Commit 14634c0

Browse files
author
Lindsay Holmwood
authored
Merge pull request #104 from section/run-tests-on-windows
Make tests run on Windows
2 parents b922dae + 466ddcf commit 14634c0

File tree

4 files changed

+44
-13
lines changed

4 files changed

+44
-13
lines changed

.github/workflows/release.yml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,6 @@ jobs:
5050
- name: Get dependencies
5151
run: |
5252
go get -v -t -d ./...
53-
if [ -f Gopkg.toml ]; then
54-
curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh
55-
dep ensure
56-
fi
5753
5854
- name: Get version from tag ref
5955
id: get_version_from_tag

.github/workflows/test.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,13 @@ jobs:
1010

1111
test:
1212
name: Run test suite
13-
runs-on: ubuntu-latest
13+
runs-on: ${{ matrix.os }}
14+
strategy:
15+
matrix:
16+
include:
17+
- os: windows-latest
18+
- os: ubuntu-latest
1419
steps:
15-
1620
- name: Set up Go 1.x
1721
uses: actions/setup-go@v2
1822
with:
@@ -25,10 +29,6 @@ jobs:
2529
- name: Get dependencies
2630
run: |
2731
go get -v -t -d ./...
28-
if [ -f Gopkg.toml ]; then
29-
curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh
30-
dep ensure
31-
fi
3232
3333
- name: Test
3434
env:

sectionctl.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"log"
77
"net/url"
88
"os"
9+
"path/filepath"
910
"time"
1011

1112
"github.com/alecthomas/kong"
@@ -32,6 +33,7 @@ type CLI struct {
3233
Version commands.VersionCmd `cmd help:"Print sectionctl version"`
3334
WhoAmI commands.WhoAmICmd `cmd name:"whoami" help:"Show information about the currently authenticated user"`
3435
Debug bool `env:"DEBUG" help:"Enable debug output"`
36+
DebugFileDir string `default:"." help:"Directory where debug output should be written"`
3537
SectionToken string `env:"SECTION_TOKEN" help:"Secret token for API auth"`
3638
SectionAPIPrefix *url.URL `default:"https://aperture.section.io" env:"SECTION_API_PREFIX"`
3739
SectionAPITimeout time.Duration `default:"30s" env:"SECTION_API_TIMEOUT" help:"Request timeout for the Section API"`
@@ -51,16 +53,17 @@ func bootstrap(c CLI, ctx *kong.Context) {
5153
}
5254
if c.Debug {
5355
filter.MinLevel = logutils.LogLevel("DEBUG")
54-
logFilename := fmt.Sprintf("sectionctl-debug-%s.log", time.Now().Format(time.RFC3339))
55-
logFile, err := os.OpenFile(logFilename, os.O_CREATE|os.O_APPEND|os.O_RDWR, 0666)
56+
logFilename := fmt.Sprintf("sectionctl-debug-%s.log", time.Now().Format("2006-01-02-15-04-05Z0700"))
57+
logFilePath := filepath.Join(c.DebugFileDir, logFilename)
58+
logFile, err := os.OpenFile(logFilePath, os.O_CREATE|os.O_APPEND|os.O_RDWR, 0666)
5659
if err != nil {
5760
panic(err)
5861
}
5962
fmt.Fprintf(logFile, "Version: %s\n", commands.VersionCmd{}.String())
6063
fmt.Fprintf(logFile, "Command: %s\n", ctx.Args)
6164
fmt.Fprintf(logFile, "PrefixURI: %s\n", api.PrefixURI)
6265
fmt.Fprintf(logFile, "Timeout: %s\n", api.Timeout)
63-
fmt.Printf("Writing debug log to: %s\n", logFilename)
66+
fmt.Printf("Writing debug log to: %s\n", logFilePath)
6467
mw := io.MultiWriter(logFile, colorableWriter)
6568
filter.Writer = mw
6669
}

sectionctl_test.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package main
2+
3+
import (
4+
"io/ioutil"
5+
"net/url"
6+
"path/filepath"
7+
"testing"
8+
9+
"github.com/alecthomas/kong"
10+
"github.com/stretchr/testify/assert"
11+
)
12+
13+
func TestBootstrapSetsUpDebugLogFile(t *testing.T) {
14+
assert := assert.New(t)
15+
16+
// Setup
17+
u, err := url.Parse("https://aperture.section.io")
18+
assert.NoError(err)
19+
d, err := ioutil.TempDir("", "sectionctl")
20+
assert.NoError(err)
21+
22+
var cli = CLI{Debug: true, SectionToken: "s3cr3t", SectionAPIPrefix: u, DebugFileDir: d}
23+
var ctx kong.Context
24+
25+
// Invoke
26+
bootstrap(cli, &ctx)
27+
28+
// Test
29+
m, err := filepath.Glob(filepath.Join(d, "*.log"))
30+
assert.NoError(err)
31+
assert.Greater(len(m), 0)
32+
}

0 commit comments

Comments
 (0)