Skip to content

Commit

Permalink
chore: refactor after discussion
Browse files Browse the repository at this point in the history
  • Loading branch information
IronCore864 committed Sep 10, 2024
1 parent 682c2aa commit a45bee7
Show file tree
Hide file tree
Showing 6 changed files with 230 additions and 172 deletions.
16 changes: 0 additions & 16 deletions internals/testintegration/pebble_another_test.go

This file was deleted.

51 changes: 0 additions & 51 deletions internals/testintegration/pebble_run_test.go

This file was deleted.

105 changes: 0 additions & 105 deletions internals/testintegration/utils.go

This file was deleted.

31 changes: 31 additions & 0 deletions tests/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Pebble Integration Tests

## Run Tests

```bash
go test -tags=integration ./tests/
```

## Developing

### Clean Test Cache

If you are adding tests and debugging, remember to clean test cache:

```bash
go clean -testcache && go test -v -tags=integration ./tests/
```

### Visual Studio Code Settings

For the VSCode Go extention to work properly with files with build tags, add the following:

```json
{
"gopls": {
"build.buildFlags": [
"-tags=integration"
]
}
}
```
67 changes: 67 additions & 0 deletions tests/main_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
//go:build integration

// Copyright (c) 2024 Canonical Ltd
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License version 3 as
// published by the Free Software Foundation.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.

package tests_test

import (
"fmt"
"os"
"os/exec"
"testing"
"time"

. "github.com/canonical/pebble/tests"
)

func TestMain(m *testing.M) {
goBuild := exec.Command("go", "build", "-o", "../pebble", "../cmd/pebble")
if err := goBuild.Run(); err != nil {
fmt.Println("Setup failed with error:", err)
os.Exit(1)
}

exitVal := m.Run()
os.Exit(exitVal)
}

func TestPebbleRunNormal(t *testing.T) {
pebbleDir := t.TempDir()

layerYAML := `
services:
demo-service:
override: replace
command: sleep 1000
startup: enabled
demo-service2:
override: replace
command: sleep 1000
startup: enabled
`[1:]

CreateLayer(t, pebbleDir, "001-simple-layer.yaml", layerYAML)

logsCh := PebbleRun(t, pebbleDir)
expected := []string{
"Started daemon",
"Service \"demo-service\" starting",
"Service \"demo-service2\" starting",
"Started default services with change",
}
if err := WaitForLogs(logsCh, expected, time.Second*3); err != nil {
t.Errorf("Error waiting for logs: %v", err)
}
}
Loading

0 comments on commit a45bee7

Please sign in to comment.