-
Notifications
You must be signed in to change notification settings - Fork 141
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: update integration tests (#434)
* feat: add more unittests * fix(tests): use the soft binary to run integration tests * fix(ci): upload coverage data * fix: daemon test idle timeout * fix: daemon flaky test * chore: add more webhook unit tests * fix(test): enable webhook integration tests * fix(tests): readd sync lock * fix(ci): collect coverage for both unit and integration tests * fix(ci): coverage test * fix(ci): remove macos and windows * fix: return the opened logger file * fix: daemon idle test * fix: testscript on windows * fix: run soft-serve in txtar background * fix(ci): collecting coverage data * fix: coverage data * fix: remove unused * fix: add browse test * feat: add stop server endpoint * fix(tests): run integration tests on windows * fix(tests): skip daemon idle timeout flaky test * fix(tests): attempt to fix daemon idle test
- Loading branch information
1 parent
d483565
commit 40d76a1
Showing
58 changed files
with
996 additions
and
187 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package access | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
) | ||
|
||
func TestGoodFromContext(t *testing.T) { | ||
ctx := WithContext(context.TODO(), AdminAccess) | ||
if ac := FromContext(ctx); ac != AdminAccess { | ||
t.Errorf("FromContext(ctx) => %d, want %d", ac, AdminAccess) | ||
} | ||
} | ||
|
||
func TestBadFromContext(t *testing.T) { | ||
ctx := context.TODO() | ||
if ac := FromContext(ctx); ac != -1 { | ||
t.Errorf("FromContext(ctx) => %d, want %d", ac, -1) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package config | ||
|
||
import ( | ||
"context" | ||
"reflect" | ||
"testing" | ||
) | ||
|
||
func TestBadFromContext(t *testing.T) { | ||
ctx := context.TODO() | ||
if c := FromContext(ctx); c != nil { | ||
t.Errorf("FromContext(ctx) => %v, want %v", c, nil) | ||
} | ||
} | ||
|
||
func TestGoodFromContext(t *testing.T) { | ||
ctx := WithContext(context.TODO(), &Config{}) | ||
if c := FromContext(ctx); c == nil { | ||
t.Errorf("FromContext(ctx) => %v, want %v", c, &Config{}) | ||
} | ||
} | ||
|
||
func TestGoodFromContextWithDefaultConfig(t *testing.T) { | ||
cfg := DefaultConfig() | ||
ctx := WithContext(context.TODO(), cfg) | ||
if c := FromContext(ctx); c == nil || !reflect.DeepEqual(c, cfg) { | ||
t.Errorf("FromContext(ctx) => %v, want %v", c, cfg) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package config | ||
|
||
import "testing" | ||
|
||
func TestNewConfigFile(t *testing.T) { | ||
for _, cfg := range []*Config{ | ||
nil, | ||
DefaultConfig(), | ||
&Config{}, | ||
} { | ||
if s := newConfigFile(cfg); s == "" { | ||
t.Errorf("newConfigFile(nil) => %q, want non-empty string", s) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,28 @@ | ||
package config | ||
|
||
import "github.com/charmbracelet/keygen" | ||
import ( | ||
"errors" | ||
|
||
"github.com/charmbracelet/keygen" | ||
) | ||
|
||
var ( | ||
// ErrNilConfig is returned when a nil config is passed to a function. | ||
ErrNilConfig = errors.New("nil config") | ||
|
||
// ErrEmptySSHKeyPath is returned when the SSH key path is empty. | ||
ErrEmptySSHKeyPath = errors.New("empty SSH key path") | ||
) | ||
|
||
// KeyPair returns the server's SSH key pair. | ||
func (c SSHConfig) KeyPair() (*keygen.SSHKeyPair, error) { | ||
return keygen.New(c.KeyPath, keygen.WithKeyType(keygen.Ed25519)) | ||
func KeyPair(cfg *Config) (*keygen.SSHKeyPair, error) { | ||
if cfg == nil { | ||
return nil, ErrNilConfig | ||
} | ||
|
||
if cfg.SSH.KeyPath == "" { | ||
return nil, ErrEmptySSHKeyPath | ||
} | ||
|
||
return keygen.New(cfg.SSH.KeyPath, keygen.WithKeyType(keygen.Ed25519)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package config | ||
|
||
import "testing" | ||
|
||
func TestBadSSHKeyPair(t *testing.T) { | ||
for _, cfg := range []*Config{ | ||
nil, | ||
{}, | ||
} { | ||
if _, err := KeyPair(cfg); err == nil { | ||
t.Errorf("cfg.SSH.KeyPair() => _, nil, want non-nil error") | ||
} | ||
} | ||
} | ||
|
||
func TestGoodSSHKeyPair(t *testing.T) { | ||
cfg := &Config{ | ||
SSH: SSHConfig{ | ||
KeyPath: "testdata/ssh_host_ed25519_key", | ||
}, | ||
} | ||
|
||
if _, err := KeyPair(cfg); err != nil { | ||
t.Errorf("cfg.SSH.KeyPair() => _, %v, want nil error", err) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package cron | ||
|
||
import ( | ||
"bytes" | ||
"context" | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/charmbracelet/log" | ||
) | ||
|
||
func TestCronLogger(t *testing.T) { | ||
var buf bytes.Buffer | ||
logger := log.New(&buf) | ||
logger.SetLevel(log.DebugLevel) | ||
clogger := cronLogger{logger} | ||
clogger.Info("foo") | ||
clogger.Error(fmt.Errorf("bar"), "test") | ||
if buf.String() != "DEBU foo\nERRO test err=bar\n" { | ||
t.Errorf("unexpected log output: %s", buf.String()) | ||
} | ||
} | ||
|
||
func TestSchedularAddRemove(t *testing.T) { | ||
s := NewScheduler(context.TODO()) | ||
id, err := s.AddFunc("* * * * *", func() {}) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
s.Remove(id) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.