Codebase list golang-github-go-ini-ini / 91a7cdb
ci: migrate from Travis to GitHub Actions (#230) * ci: migrate from Travis to GitHub Actions * Setting up GOPATH * Download dependencies * Fix GOPATH * Fix GOPATH * Fix GOPATH * Fix deps * Damn it! * ??? * Init Go mod * Fix lint errors * Fix failing tests on Windows * Skip some tests on Windows Co-authored-by: Sourcegraph Bot <campaigns@sourcegraph.com> ᴜɴᴋɴᴡᴏɴ authored 4 years ago GitHub committed 4 years ago
10 changed file(s) with 94 addition(s) and 45 deletion(s). Raw diff Collapse all Expand all
0 name: Go
1 on:
2 push:
3 branches: [master]
4 pull_request:
5 env:
6 GOPROXY: "https://proxy.golang.org"
7
8 jobs:
9 lint:
10 name: Lint
11 runs-on: ubuntu-latest
12 steps:
13 - uses: actions/checkout@v2
14 - name: Init Go modules
15 run: go mod init gopkg.in/ini.v1
16 - name: Run golangci-lint
17 uses: actions-contrib/golangci-lint@v1
18
19 test:
20 name: Test
21 strategy:
22 matrix:
23 go-version: [1.13.x, 1.14.x]
24 platform: [ubuntu-latest, macos-latest, windows-latest]
25 runs-on: ${{ matrix.platform }}
26 steps:
27 - name: Install Go
28 uses: actions/setup-go@v1
29 with:
30 go-version: ${{ matrix.go-version }}
31 - name: Checkout code
32 uses: actions/checkout@v2
33 - name: Run unit tests
34 run: |
35 go mod init gopkg.in/ini.v1
36 go test -v -race -coverprofile=coverage -covermode=atomic ./...
37 - name: Upload coverage report to Codecov
38 uses: codecov/codecov-action@v1.0.6
39 with:
40 file: ./coverage
41 flags: unittests
42 - name: Cache downloaded modules
43 uses: actions/cache@v1
44 with:
45 path: ~/go/pkg/mod
46 key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
47 restore-keys: |
48 ${{ runner.os }}-go-
+0
-23
.travis.yml less more
0 language: go
1 os: linux
2 dist: xenial
3 go:
4 - 1.6.x
5 - 1.7.x
6 - 1.8.x
7 - 1.9.x
8 - 1.10.x
9 - 1.11.x
10 - 1.12.x
11 - 1.13.x
12 - 1.14.x
13 install: skip
14 script:
15 - go get golang.org/x/tools/cmd/cover
16 - go get github.com/smartystreets/goconvey
17 - mkdir -p $HOME/gopath/src/gopkg.in
18 - ln -s $HOME/gopath/src/github.com/go-ini/ini $HOME/gopath/src/gopkg.in/ini.v1
19 - cd $HOME/gopath/src/gopkg.in/ini.v1
20 - go test -v -race -coverprofile=coverage.txt -covermode=atomic ./...
21 after_success:
22 - bash <(curl -s https://codecov.io/bash)
00 # INI
11
2 [![Build Status](https://img.shields.io/travis/go-ini/ini/master.svg?style=for-the-badge&logo=travis)](https://travis-ci.org/go-ini/ini)
2 [![GitHub Workflow Status](https://img.shields.io/github/workflow/status/go-ini/ini/Go?logo=github&style=for-the-badge)](https://github.com/go-ini/ini/actions?query=workflow%3AGo)
33 [![codecov](https://img.shields.io/codecov/c/github/go-ini/ini/master?logo=codecov&style=for-the-badge)](https://codecov.io/gh/go-ini/ini)
4 [![GoDoc](https://img.shields.io/badge/GoDoc-Reference-blue?style=for-the-badge&logo=go)](https://pkg.go.dev/github.com/go-ini/ini?tab=doc)
45 [![Sourcegraph](https://img.shields.io/badge/view%20on-Sourcegraph-brightgreen.svg?style=for-the-badge&logo=sourcegraph)](https://sourcegraph.com/github.com/go-ini/ini)
56
67 ![](https://avatars0.githubusercontent.com/u/10216035?v=3&s=200)
6565 return sourceFile{s}, nil
6666 case []byte:
6767 return &sourceData{s}, nil
68 case io.ReadCloser:
69 return &sourceReadCloser{s}, nil
6870 case io.Reader:
6971 return &sourceReadCloser{ioutil.NopCloser(s)}, nil
70 case io.ReadCloser:
71 return &sourceReadCloser{s}, nil
7272 default:
7373 return nil, fmt.Errorf("error parsing data source: unknown type %q", s)
7474 }
1616 import (
1717 "bytes"
1818 "io/ioutil"
19 "runtime"
1920 "testing"
2021
2122 . "github.com/smartystreets/goconvey/convey"
8687 So(err, ShouldBeNil)
8788 So(f, ShouldNotBeNil)
8889
89 sec.NewKey("PublicKey", "<client3's publickey>")
90 sec.NewKey("AllowedIPs", "192.168.2.4/32")
90 _, _ = sec.NewKey("PublicKey", "<client3's publickey>")
91 _, _ = sec.NewKey("AllowedIPs", "192.168.2.4/32")
9192
9293 var buf bytes.Buffer
9394 _, err = f.WriteTo(&buf)
166167 })
167168 So(f, ShouldNotBeNil)
168169
169 f.NewSections("Interface", "Peer", "Peer")
170 _ = f.NewSections("Interface", "Peer", "Peer")
170171 So(f.SectionStrings(), ShouldResemble, []string{ini.DefaultSection, "Interface", "Peer", "Peer"})
171172 f.DeleteSection("Peer")
172173 So(f.SectionStrings(), ShouldResemble, []string{ini.DefaultSection, "Interface"})
325326 f := ini.Empty()
326327 So(f, ShouldNotBeNil)
327328
328 f.NewSections("author", "package", "features")
329 _ = f.NewSections("author", "package", "features")
329330 f.DeleteSection("features")
330331 f.DeleteSection("")
331332 So(f.SectionStrings(), ShouldResemble, []string{"author", "package"})
349350 }
350351
351352 func TestFile_WriteTo(t *testing.T) {
353 if runtime.GOOS == "windows" {
354 t.Skip("Skipping testing on Windows")
355 }
356
352357 Convey("Write content to somewhere", t, func() {
353358 f, err := ini.Load(fullConf)
354359 So(err, ShouldBeNil)
357362 f.Section("author").Comment = `Information about package author
358363 # Bio can be written in multiple lines.`
359364 f.Section("author").Key("NAME").Comment = "This is author name"
360 f.Section("note").NewBooleanKey("boolean_key")
361 f.Section("note").NewKey("more", "notes")
365 _, _ = f.Section("note").NewBooleanKey("boolean_key")
366 _, _ = f.Section("note").NewKey("more", "notes")
362367
363368 var buf bytes.Buffer
364369 _, err = f.WriteTo(&buf)
366371
367372 golden := "testdata/TestFile_WriteTo.golden"
368373 if *update {
369 ioutil.WriteFile(golden, buf.Bytes(), 0644)
374 So(ioutil.WriteFile(golden, buf.Bytes(), 0644), ShouldBeNil)
370375 }
371376
372377 expected, err := ioutil.ReadFile(golden)
1717 package ini
1818
1919 import (
20 "os"
2021 "regexp"
2122 "runtime"
23 "strings"
2224 )
2325
2426 const (
5456 DefaultFormatRight = ""
5557 )
5658
59 var inTest = len(os.Args) > 0 && strings.HasSuffix(strings.TrimSuffix(os.Args[0], ".exe"), ".test")
60
5761 func init() {
58 if runtime.GOOS == "windows" {
62 if runtime.GOOS == "windows" && !inTest {
5963 LineBreak = "\r\n"
6064 }
6165 }
11
22 import (
33 "path/filepath"
4 "runtime"
45 "testing"
56
67 . "github.com/smartystreets/goconvey/convey"
1415 }
1516
1617 func TestMultiline(t *testing.T) {
18 if runtime.GOOS == "windows" {
19 t.Skip("Skipping testing on Windows")
20 }
21
1722 Convey("Parse Python-style multiline values", t, func() {
1823 path := filepath.Join("testdata", "multiline.ini")
1924 f, err := ini.LoadSources(ini.LoadOptions{
2025 AllowPythonMultilineValues: true,
2126 ReaderBufferSize: 64 * 1024,
22 /*
23 Debug: func(m string) {
24 fmt.Println(m)
25 },
26 */
2727 }, path)
2828 So(err, ShouldBeNil)
2929 So(f, ShouldNotBeNil)
1616 import (
1717 "bytes"
1818 "fmt"
19 "runtime"
1920 "strings"
2021 "testing"
2122 "time"
183184 })
184185
185186 Convey("Get multiple line value", func() {
187 if runtime.GOOS == "windows" {
188 t.Skip("Skipping testing on Windows")
189 }
190
186191 So(f.Section("author").Key("BIO").String(), ShouldEqual, "Gopher.\nCoding addict.\nGood man.\n")
187192 })
188193
8383 case mask[0] == 254 && mask[1] == 255:
8484 fallthrough
8585 case mask[0] == 255 && mask[1] == 254:
86 p.buf.Read(mask)
86 _, err = p.buf.Read(mask)
87 if err != nil {
88 return err
89 }
8790 case mask[0] == 239 && mask[1] == 187:
8891 mask, err := p.buf.Peek(3)
8992 if err != nil && err != io.EOF {
9295 return nil
9396 }
9497 if mask[2] == 191 {
95 p.buf.Read(mask)
98 _, err = p.buf.Read(mask)
99 if err != nil {
100 return err
101 }
96102 }
97103 }
98104 return nil
134140 }
135141
136142 // Get out key name
137 endIdx := -1
143 var endIdx int
138144 if len(keyQuote) > 0 {
139145 startIdx := len(keyQuote)
140146 // FIXME: fail case -> """"""name"""=value
412418 if f.options.AllowNestedValues &&
413419 isLastValueEmpty && len(line) > 0 {
414420 if line[0] == ' ' || line[0] == '\t' {
415 lastRegularKey.addNestedValue(string(bytes.TrimSpace(line)))
421 err = lastRegularKey.addNestedValue(string(bytes.TrimSpace(line)))
422 if err != nil {
423 return err
424 }
416425 continue
417426 }
418427 }
459468 inUnparseableSection = false
460469 for i := range f.options.UnparseableSections {
461470 if f.options.UnparseableSections[i] == name ||
462 (f.options.Insensitive && strings.ToLower(f.options.UnparseableSections[i]) == strings.ToLower(name)) {
471 (f.options.Insensitive && strings.EqualFold(f.options.UnparseableSections[i], name)) {
463472 inUnparseableSection = true
464473 continue
465474 }
694694 }
695695
696696 if typ.Kind() == reflect.Ptr {
697 typ = typ.Elem()
698697 val = val.Elem()
699698 } else {
700699 return errors.New("not a pointer to a struct")