Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/push.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ jobs:
- name: checkout main branch
uses: actions/checkout@v4

- uses: actions/setup-go@v4
- uses: actions/setup-go@v5
with:
go-version: 1.22
go-version: '1.25'

- run: go test -coverprofile=cover.out ./...
- run: go test -v -race -coverprofile=cover.out ./...

- name: checkout covrage branch
uses: actions/checkout@v4
Expand Down
16 changes: 11 additions & 5 deletions .github/workflows/validate.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,25 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: extractions/setup-just@v2
- run: just lint
- uses: actions/setup-go@v5
with:
go-version: '1.25'
- uses: golangci/golangci-lint-action@v7
with:
version: v2.6.1

test:
name: Unit Tests
runs-on: ubuntu-latest
strategy:
matrix:
go: ["1.21", "1.22"]
go: ["1.24", "1.25"]
steps:
- uses: actions/checkout@v4
- uses: extractions/setup-just@v2
- run: GO_VERSION=${{ matrix.go }} just test
- uses: actions/setup-go@v5
with:
go-version: ${{ matrix.go }}
- run: go test -race ./...

inttest:
name: Integration Tests
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
.idea/
confd-basic*.zip
out
cover.out
*.test
28 changes: 28 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
version: "2"
linters:
enable:
- errorlint
settings:
errcheck:
check-type-assertions: true
check-blank: true
errorlint:
errorf: true
asserts: true
comparison: true
exclusions:
generated: lax
paths:
- third_party$
- builtin$
- examples$
formatters:
enable:
- gofmt
- goimports
exclusions:
generated: lax
paths:
- third_party$
- builtin$
- examples$
25 changes: 2 additions & 23 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,28 +1,11 @@
ARG GO_VER=1.20
ARG GOLANGCI_VER=1.51
ARG GO_VER=1.24

FROM golang:${GO_VER} as base
WORKDIR /src
COPY go.mod go.sum /src/
RUN --mount=type=cache,target=/go/pkg/mod \
go mod download -x

FROM golangci/golangci-lint:v${GOLANGCI_VER}-alpine AS lint-base

FROM base AS lint
RUN --mount=target=. \
--mount=from=lint-base,src=/usr/bin/golangci-lint,target=/usr/bin/golangci-lint \
--mount=type=cache,target=/go/pkg/mod \
--mount=type=cache,target=/root/.cache/go-build \
--mount=type=cache,target=/root/.cache/golangci-lint \
golangci-lint run --timeout 10m0s ./...

FROM base as unittest
RUN --mount=target=/src \
--mount=type=cache,target=/go/pkg/mod \
--mount=type=cache,target=/root/.cache/go-build \
mkdir /out && \
go test -v -race -coverprofile=/out/cover.out ./... | tee /out/test.stdout

FROM base AS inttest
RUN apt update && apt install -y \
Expand All @@ -37,8 +20,4 @@ RUN --mount=target=/src \
go test --tags=inttest -c -o /out/inttest.test
WORKDIR /out
COPY inttest/wait-for-hello.sh .
CMD ./inttest.test -test.v -test.race


FROM scratch AS unittest-coverage
COPY --from=unittest /out /
CMD ./inttest.test -test.v -test.race
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

This library is used to create client applications for connecting to network devices via NETCONF.

Like Go itself, only the latest two Go versions are tested and supported (Go 1.24 or Go 1.23).
Like Go itself, only the latest two Go versions are tested and supported (Go 1.24 or Go 1.26).

NOTICE: The API is pretty stable but not finalized yet. So changes may happen before a 1.0 release. Check for API changes when you upgrade.

Expand Down
4 changes: 2 additions & 2 deletions example_ssh_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import (
"log"
"time"

"golang.org/x/crypto/ssh"
"nemith.io/netconf"
ncssh "nemith.io/netconf/transport/ssh"
"golang.org/x/crypto/ssh"
)

const sshAddr = "myrouter.example.com:830"
Expand All @@ -27,7 +27,7 @@ func Example_ssh() {
if err != nil {
panic(err)
}
defer transport.Close()
defer transport.Close() // nolint:errcheck

session, err := netconf.Open(transport)
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions example_tls_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,13 @@ func Example_tls() {
if err != nil {
panic(err)
}
defer transport.Close()
defer transport.Close() // nolint:errcheck

session, err := netconf.Open(transport)
if err != nil {
panic(err)
}
defer session.Close(context.Background())
defer session.Close(context.Background()) // nolint:errcheck

// timeout for the call itself.
ctx, cancel = context.WithTimeout(ctx, 5*time.Second)
Expand Down
12 changes: 5 additions & 7 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
module nemith.io/netconf

go 1.23.0

toolchain go1.24.1
go 1.24.10

require (
github.com/stretchr/testify v1.11.0
golang.org/x/crypto v0.34.0
github.com/stretchr/testify v1.11.1
golang.org/x/crypto v0.45.0
)

require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
golang.org/x/exp v0.0.0-20230817173708-d852ddb80c63
golang.org/x/sys v0.30.0 // indirect
golang.org/x/exp v0.0.0-20251125195548-87e1e737ad39
golang.org/x/sys v0.38.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
20 changes: 10 additions & 10 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/testify v1.11.0 h1:ib4sjIrwZKxE5u/Japgo/7SJV3PvgjGiRNAvTVGqQl8=
github.com/stretchr/testify v1.11.0/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U=
golang.org/x/crypto v0.34.0 h1:+/C6tk6rf/+t5DhUketUbD1aNGqiSX3j15Z6xuIDlBA=
golang.org/x/crypto v0.34.0/go.mod h1:dy7dXNW32cAb/6/PRuTNsix8T+vJAqvuIy5Bli/x0YQ=
golang.org/x/exp v0.0.0-20230817173708-d852ddb80c63 h1:m64FZMko/V45gv0bNmrNYoDEq8U5YUhetc9cBWKS1TQ=
golang.org/x/exp v0.0.0-20230817173708-d852ddb80c63/go.mod h1:0v4NqG35kSWCMzLaMeX+IQrlSnVE/bqGSyC2cz/9Le8=
golang.org/x/sys v0.30.0 h1:QjkSwP/36a20jFYWkSue1YwXzLmsV5Gfq7Eiy72C1uc=
golang.org/x/sys v0.30.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/term v0.29.0 h1:L6pJp37ocefwRRtYPKSWOWzOtWSxVajvz2ldH/xi3iU=
golang.org/x/term v0.29.0/go.mod h1:6bl4lRlvVuDgSf3179VpIxBF0o10JUpXWOnI7nErv7s=
github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U=
github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U=
golang.org/x/crypto v0.45.0 h1:jMBrvKuj23MTlT0bQEOBcAE0mjg8mK9RXFhRH6nyF3Q=
golang.org/x/crypto v0.45.0/go.mod h1:XTGrrkGJve7CYK7J8PEww4aY7gM3qMCElcJQ8n8JdX4=
golang.org/x/exp v0.0.0-20251125195548-87e1e737ad39 h1:DHNhtq3sNNzrvduZZIiFyXWOL9IWaDPHqTnLJp+rCBY=
golang.org/x/exp v0.0.0-20251125195548-87e1e737ad39/go.mod h1:46edojNIoXTNOhySWIWdix628clX9ODXwPsQuG6hsK0=
golang.org/x/sys v0.38.0 h1:3yZWxaJjBmCWXqhN1qh02AkOnCQ1poK6oF+a7xWL6Gc=
golang.org/x/sys v0.38.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks=
golang.org/x/term v0.37.0 h1:8EGAD0qCmHYZg6J17DvsMy9/wJ7/D/4pV/wfnld5lTU=
golang.org/x/term v0.37.0/go.mod h1:5pB4lxRNYYVZuTLmy8oR2BH8dflOR+IbTYFD8fi3254=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
Expand Down
2 changes: 1 addition & 1 deletion inttest/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,6 @@ CONFD_IMAGE=conf-basic:7.8 just ceos
Netopeer2 is an opensource NETCONF server. A docker image is automaticall built when running the tests so no additional work is needed.

```plain
cd inttent
cd inttest
just netopeer2
```
2 changes: 1 addition & 1 deletion inttest/justfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ args := '\
--exit-code-from inttest
'

all: csrx ceos confd netopeer2
all: csrx ceos confd

csrx:
#!/usr/bin/env bash
Expand Down
18 changes: 3 additions & 15 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,14 @@ pwd := justfile_directory()
@list:
just --list

golangci_version := "1.51"
go_version := env_var_or_default("GO_VERSION", "1.20")

test *args:
docker buildx build \
--build-arg GO_VER={{ go_version }} \
--output out/test \
--target unittest-coverage . \
{{ args }}
cat out/test/test.stdout
go test -v -race ./... {{ args }}

lint *args:
@docker buildx build \
--build-arg GO_VER={{ go_version }} \
--build-arg GOLANGCI_VER={{ golangci_version }} \
--target lint . \
{{ args }}
golangci-lint run --timeout 10m0s ./... {{ args }}

inttest:
just inttest/all

clean:
@rm -rf ./out
@rm -rf ./out
4 changes: 2 additions & 2 deletions ops.go
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ type LockReq struct {

func (s *Session) Lock(ctx context.Context, target Datastore) error {
req := LockReq{
XMLName: xml.Name{Local: "lock"},
XMLName: xml.Name{Space: "urn:ietf:params:xml:ns:netconf:base:1.0", Local: "lock"},
Target: target,
}

Expand All @@ -332,7 +332,7 @@ func (s *Session) Lock(ctx context.Context, target Datastore) error {

func (s *Session) Unlock(ctx context.Context, target Datastore) error {
req := LockReq{
XMLName: xml.Name{Local: "unlock"},
XMLName: xml.Name{Space: "urn:ietf:params:xml:ns:netconf:base:1.0", Local: "unlock"},
Target: target,
}

Expand Down
4 changes: 2 additions & 2 deletions ops_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ func TestLock(t *testing.T) {
{
target: Candidate,
matches: []*regexp.Regexp{
regexp.MustCompile(`<lock>\S*<target>\S*<candidate/>\S*</target>\S*</lock>`),
regexp.MustCompile(`<lock xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">\S*<target>\S*<candidate/>\S*</target>\S*</lock>`),
},
},
}
Expand Down Expand Up @@ -373,7 +373,7 @@ func TestUnlock(t *testing.T) {
{
target: Candidate,
matches: []*regexp.Regexp{
regexp.MustCompile(`<unlock>\S*<target>\S*<candidate/>\S*</target>\S*</unlock>`),
regexp.MustCompile(`<unlock xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">\S*<target>\S*<candidate/>\S*</target>\S*</unlock>`),
},
},
}
Expand Down
9 changes: 4 additions & 5 deletions session.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ func Open(transport transport.Transport, opts ...SessionOption) (*Session, error

// this needs a timeout of some sort.
if err := s.handshake(); err != nil {
s.tr.Close()
s.tr.Close() // nolint:errcheck // TODO: catch and log err
return nil, err
}

Expand All @@ -115,8 +115,7 @@ func (s *Session) handshake() error {
if err != nil {
return err
}
// TODO: capture this error some how (ah defer and errors)
defer r.Close()
defer r.Close() // nolint:errcheck // TODO: catch and log err

var serverMsg helloMsg
if err := xml.NewDecoder(r).Decode(&serverMsg); err != nil {
Expand Down Expand Up @@ -188,7 +187,7 @@ func (s *Session) recvMsg() error {
if err != nil {
return err
}
defer r.Close()
defer r.Close() // nolint:errcheck // TODO: catch error and log
dec := xml.NewDecoder(r)

root, err := startElement(dec)
Expand Down Expand Up @@ -379,7 +378,7 @@ func (s *Session) Close(ctx context.Context) error {
}
}

if callErr != io.EOF {
if !errors.Is(callErr, io.EOF) {
return callErr
}

Expand Down
12 changes: 7 additions & 5 deletions transport/frame.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,9 @@ func (r *chunkReader) Read(p []byte) (int, error) {
return 0, ErrInvalidIO
}
// make sure we can't try to read more than the max chunk
p = p[:maxChunk]
if len(p) > maxChunk {
p = p[:maxChunk]
}

// done with existing chunk so grab the next one
if r.chunkLeft <= 0 {
Expand Down Expand Up @@ -271,10 +273,10 @@ func (r *chunkReader) Close() error {
// readHeader return io.EOF when it encounter the end-of-frame
// marker ("\n##\n")
err := r.readHeader()
switch err {
case nil:
switch {
case err == nil:
break
case io.EOF:
case errors.Is(err, io.EOF):
return nil
default:
return err
Expand Down Expand Up @@ -381,7 +383,7 @@ func (r *eomReader) Close() error {
var err error
for err == nil {
_, err = r.ReadByte()
if err == io.EOF {
if errors.Is(err, io.EOF) {
return nil
}
}
Expand Down
Loading