Fix Go code formatting issues

Run gofmt -w . to fix formatting issues detected by CI:
- Fix indentation (spaces to tabs)
- Add missing newlines at end of files
- Remove trailing whitespace
This commit is contained in:
Nick Bozhenko
2025-07-16 17:13:46 -04:00
parent 06ff8718ad
commit b9bed90904
121 changed files with 4855 additions and 2904 deletions
+17 -17
View File
@@ -9,9 +9,9 @@ import (
)
type CmdSuite struct {
mockProgress *MockCmdProgress
collectionFactory *deb.CollectionFactory
mockContext *MockCmdContext
mockProgress *MockCmdProgress
collectionFactory *deb.CollectionFactory
mockContext *MockCmdContext
}
var _ = Suite(&CmdSuite{})
@@ -35,7 +35,7 @@ func (s *CmdSuite) SetUpTest(c *C) {
func (s *CmdSuite) TestListPackagesRefListBasic(c *C) {
// Test basic functionality of ListPackagesRefList
reflist := &deb.PackageRefList{}
err := ListPackagesRefList(reflist, s.collectionFactory)
c.Check(err, IsNil)
}
@@ -43,7 +43,7 @@ func (s *CmdSuite) TestListPackagesRefListBasic(c *C) {
func (s *CmdSuite) TestPrintPackageListBasic(c *C) {
// Test basic PrintPackageList functionality
packageList := deb.NewPackageList()
err := PrintPackageList(packageList, "", " ")
c.Check(err, IsNil)
}
@@ -54,18 +54,18 @@ type MockCmdProgress struct {
messages []string
}
func (m *MockCmdProgress) Printf(msg string, a ...interface{}) {}
func (m *MockCmdProgress) ColoredPrintf(msg string, a ...interface{}) {}
func (m *MockCmdProgress) PrintfStdErr(msg string, a ...interface{}) {}
func (m *MockCmdProgress) Flush() {}
func (m *MockCmdProgress) Start() {}
func (m *MockCmdProgress) Shutdown() {}
func (m *MockCmdProgress) Printf(msg string, a ...interface{}) {}
func (m *MockCmdProgress) ColoredPrintf(msg string, a ...interface{}) {}
func (m *MockCmdProgress) PrintfStdErr(msg string, a ...interface{}) {}
func (m *MockCmdProgress) Flush() {}
func (m *MockCmdProgress) Start() {}
func (m *MockCmdProgress) Shutdown() {}
func (m *MockCmdProgress) InitBar(count int64, isBytes bool, barType aptly.BarType) {}
func (m *MockCmdProgress) ShutdownBar() {}
func (m *MockCmdProgress) AddBar(count int) {}
func (m *MockCmdProgress) SetBar(count int) {}
func (m *MockCmdProgress) PrintfBar(msg string, a ...interface{}) {}
func (m *MockCmdProgress) Write(p []byte) (n int, err error) { return len(p), nil }
func (m *MockCmdProgress) ShutdownBar() {}
func (m *MockCmdProgress) AddBar(count int) {}
func (m *MockCmdProgress) SetBar(count int) {}
func (m *MockCmdProgress) PrintfBar(msg string, a ...interface{}) {}
func (m *MockCmdProgress) Write(p []byte) (n int, err error) { return len(p), nil }
type MockCmdContext struct {
progress *MockCmdProgress
@@ -77,4 +77,4 @@ func (m *MockCmdContext) Progress() aptly.Progress { return
func (m *MockCmdContext) NewCollectionFactory() *deb.CollectionFactory { return m.collectionFactory }
func (m *MockCmdContext) Config() *utils.ConfigStructure { return &utils.ConfigStructure{} }
// Note: Complex integration tests have been simplified for compilation compatibility.
// Note: Complex integration tests have been simplified for compilation compatibility.
+29 -29
View File
@@ -35,7 +35,7 @@ func (s *ContextSuite) TearDownTest(c *C) {
func (s *ContextSuite) TestInitContextSuccess(c *C) {
// Test successful context initialization
flags := flag.NewFlagSet("test", flag.ContinueOnError)
err := InitContext(flags)
c.Check(err, IsNil)
c.Check(context, NotNil)
@@ -45,12 +45,12 @@ func (s *ContextSuite) TestInitContextSuccess(c *C) {
func (s *ContextSuite) TestInitContextPanic(c *C) {
// Test that initializing context twice causes panic
flags := flag.NewFlagSet("test", flag.ContinueOnError)
// First initialization should succeed
err := InitContext(flags)
c.Check(err, IsNil)
c.Check(context, NotNil)
// Second initialization should panic
c.Check(func() { InitContext(flags) }, Panics, "context already initialized")
}
@@ -59,12 +59,12 @@ func (s *ContextSuite) TestInitContextError(c *C) {
// Test context initialization with invalid flags
// This tests the error path where ctx.NewContext might fail
flags := flag.NewFlagSet("test", flag.ContinueOnError)
// Add some invalid flag configuration that might cause NewContext to fail
// Note: This depends on the ctx.NewContext implementation details
flags.String("invalid-config", "/nonexistent/path/to/config", "invalid config")
flags.Set("invalid-config", "/nonexistent/path/to/config")
err := InitContext(flags)
// The error handling depends on the ctx.NewContext implementation
// If it doesn't fail with invalid paths, the test still validates the error path exists
@@ -85,10 +85,10 @@ func (s *ContextSuite) TestGetContextBeforeInit(c *C) {
func (s *ContextSuite) TestGetContextAfterInit(c *C) {
// Test GetContext after successful initialization
flags := flag.NewFlagSet("test", flag.ContinueOnError)
err := InitContext(flags)
c.Check(err, IsNil)
result := GetContext()
c.Check(result, NotNil)
c.Check(result, Equals, context)
@@ -97,11 +97,11 @@ func (s *ContextSuite) TestGetContextAfterInit(c *C) {
func (s *ContextSuite) TestShutdownContext(c *C) {
// Test ShutdownContext function
flags := flag.NewFlagSet("test", flag.ContinueOnError)
err := InitContext(flags)
c.Check(err, IsNil)
c.Check(context, NotNil)
// ShutdownContext should not panic and should call context.Shutdown()
c.Check(func() { ShutdownContext() }, Not(Panics))
}
@@ -109,7 +109,7 @@ func (s *ContextSuite) TestShutdownContext(c *C) {
func (s *ContextSuite) TestShutdownContextNil(c *C) {
// Test ShutdownContext when context is nil (should panic or handle gracefully)
context = nil
// This will panic if context is nil, which might be expected behavior
c.Check(func() { ShutdownContext() }, Panics, ".*")
}
@@ -117,11 +117,11 @@ func (s *ContextSuite) TestShutdownContextNil(c *C) {
func (s *ContextSuite) TestCleanupContext(c *C) {
// Test CleanupContext function
flags := flag.NewFlagSet("test", flag.ContinueOnError)
err := InitContext(flags)
c.Check(err, IsNil)
c.Check(context, NotNil)
// CleanupContext should not panic and should call context.Cleanup()
c.Check(func() { CleanupContext() }, Not(Panics))
}
@@ -129,7 +129,7 @@ func (s *ContextSuite) TestCleanupContext(c *C) {
func (s *ContextSuite) TestCleanupContextNil(c *C) {
// Test CleanupContext when context is nil (should panic or handle gracefully)
context = nil
// This will panic if context is nil, which might be expected behavior
c.Check(func() { CleanupContext() }, Panics, ".*")
}
@@ -137,24 +137,24 @@ func (s *ContextSuite) TestCleanupContextNil(c *C) {
func (s *ContextSuite) TestContextLifecycle(c *C) {
// Test complete context lifecycle: init -> use -> cleanup -> shutdown
flags := flag.NewFlagSet("test", flag.ContinueOnError)
// Initialize
err := InitContext(flags)
c.Check(err, IsNil)
c.Check(context, NotNil)
// Use
ctx := GetContext()
c.Check(ctx, NotNil)
c.Check(ctx, Equals, context)
// Cleanup
c.Check(func() { CleanupContext() }, Not(Panics))
// Context should still exist after cleanup
c.Check(context, NotNil)
c.Check(GetContext(), NotNil)
// Shutdown
c.Check(func() { ShutdownContext() }, Not(Panics))
}
@@ -162,10 +162,10 @@ func (s *ContextSuite) TestContextLifecycle(c *C) {
func (s *ContextSuite) TestMultipleCleanups(c *C) {
// Test calling CleanupContext multiple times
flags := flag.NewFlagSet("test", flag.ContinueOnError)
err := InitContext(flags)
c.Check(err, IsNil)
// Multiple cleanups should not cause issues
c.Check(func() { CleanupContext() }, Not(Panics))
c.Check(func() { CleanupContext() }, Not(Panics))
@@ -175,19 +175,19 @@ func (s *ContextSuite) TestMultipleCleanups(c *C) {
func (s *ContextSuite) TestContextVariableIsolation(c *C) {
// Test that the context variable is properly managed
c.Check(context, IsNil)
flags := flag.NewFlagSet("test", flag.ContinueOnError)
err := InitContext(flags)
c.Check(err, IsNil)
// Store reference
originalContext := context
c.Check(originalContext, NotNil)
// GetContext should return the same instance
retrievedContext := GetContext()
c.Check(retrievedContext, Equals, originalContext)
// Context variable should be the same
c.Check(context, Equals, originalContext)
}
@@ -195,8 +195,8 @@ func (s *ContextSuite) TestContextVariableIsolation(c *C) {
func (s *ContextSuite) TestFlagSetVariations(c *C) {
// Test InitContext with different FlagSet configurations
testCases := []struct {
name string
setupFn func() *flag.FlagSet
name string
setupFn func() *flag.FlagSet
}{
{
name: "empty flagset",
@@ -223,18 +223,18 @@ func (s *ContextSuite) TestFlagSetVariations(c *C) {
},
},
}
for _, tc := range testCases {
// Reset context for each test case
if context != nil {
context.Shutdown()
context = nil
}
flags := tc.setupFn()
err := InitContext(flags)
c.Check(err, IsNil, Commentf("Failed for test case: %s", tc.name))
c.Check(context, NotNil, Commentf("Context is nil for test case: %s", tc.name))
c.Check(GetContext(), NotNil, Commentf("GetContext returned nil for test case: %s", tc.name))
}
}
}
+13 -13
View File
@@ -40,7 +40,7 @@ func (s *DBCleanupSuite) TestMakeCmdDBCleanup(c *C) {
func (s *DBCleanupSuite) TestDBCleanupFlags(c *C) {
err := s.cmd.Flag.Set("dry-run", "true")
c.Check(err, IsNil)
err = s.cmd.Flag.Set("verbose", "true")
c.Check(err, IsNil)
}
@@ -49,17 +49,17 @@ func (s *DBCleanupSuite) TestDBCleanupFlags(c *C) {
type MockDBProgress struct{}
func (m *MockDBProgress) Printf(msg string, a ...interface{}) {}
func (m *MockDBProgress) ColoredPrintf(msg string, a ...interface{}) {}
func (m *MockDBProgress) PrintfStdErr(msg string, a ...interface{}) {}
func (m *MockDBProgress) Flush() {}
func (m *MockDBProgress) Start() {}
func (m *MockDBProgress) Shutdown() {}
func (m *MockDBProgress) Printf(msg string, a ...interface{}) {}
func (m *MockDBProgress) ColoredPrintf(msg string, a ...interface{}) {}
func (m *MockDBProgress) PrintfStdErr(msg string, a ...interface{}) {}
func (m *MockDBProgress) Flush() {}
func (m *MockDBProgress) Start() {}
func (m *MockDBProgress) Shutdown() {}
func (m *MockDBProgress) InitBar(count int64, isBytes bool, barType aptly.BarType) {}
func (m *MockDBProgress) ShutdownBar() {}
func (m *MockDBProgress) AddBar(count int) {}
func (m *MockDBProgress) SetBar(count int) {}
func (m *MockDBProgress) PrintfBar(msg string, a ...interface{}) {}
func (m *MockDBProgress) Write(p []byte) (n int, err error) { return len(p), nil }
func (m *MockDBProgress) ShutdownBar() {}
func (m *MockDBProgress) AddBar(count int) {}
func (m *MockDBProgress) SetBar(count int) {}
func (m *MockDBProgress) PrintfBar(msg string, a ...interface{}) {}
func (m *MockDBProgress) Write(p []byte) (n int, err error) { return len(p), nil }
// Note: Complex integration tests have been simplified for compilation compatibility.
// Note: Complex integration tests have been simplified for compilation compatibility.
+43 -43
View File
@@ -5,8 +5,8 @@ import (
"fmt"
"testing"
"github.com/aptly-dev/aptly/deb"
ctx "github.com/aptly-dev/aptly/context"
"github.com/aptly-dev/aptly/deb"
"github.com/smira/commander"
"github.com/smira/flag"
. "gopkg.in/check.v1"
@@ -57,7 +57,7 @@ func (s *DBRecoverSuite) TearDownTest(c *C) {
func (s *DBRecoverSuite) setupMockContext(c *C) {
// Create a mock context for testing
flags := flag.NewFlagSet("test", flag.ContinueOnError)
err := InitContext(flags)
c.Assert(err, IsNil)
}
@@ -65,13 +65,13 @@ func (s *DBRecoverSuite) setupMockContext(c *C) {
func (s *DBRecoverSuite) TestMakeCmdDBRecover(c *C) {
// Test that makeCmdDBRecover creates a proper command
cmd := makeCmdDBRecover()
c.Check(cmd, NotNil)
c.Check(cmd.Run, NotNil)
c.Check(cmd.UsageLine, Equals, "recover")
c.Check(cmd.Short, Equals, "recover DB after crash")
c.Check(cmd.Long, Not(Equals), "")
// Check that the command has the right structure
c.Check(cmd.Long, Matches, "(?s).*Database recover.*")
c.Check(cmd.Long, Matches, "(?s).*Example:.*aptly db recover.*")
@@ -80,7 +80,7 @@ func (s *DBRecoverSuite) TestMakeCmdDBRecover(c *C) {
func (s *DBRecoverSuite) TestAptlyDBRecoverWithArgs(c *C) {
// Test aptlyDBRecover with arguments (should fail)
s.setupMockContext(c)
err := aptlyDBRecover(s.cmd, []string{"extra", "args"})
c.Check(err, Equals, commander.ErrCommandError)
}
@@ -88,7 +88,7 @@ func (s *DBRecoverSuite) TestAptlyDBRecoverWithArgs(c *C) {
func (s *DBRecoverSuite) TestAptlyDBRecoverNoArgs(c *C) {
// Test aptlyDBRecover with no arguments
s.setupMockContext(c)
// This will likely fail due to missing database, but tests the flow
err := aptlyDBRecover(s.cmd, []string{})
// We expect an error since we don't have a real database setup
@@ -98,7 +98,7 @@ func (s *DBRecoverSuite) TestAptlyDBRecoverNoArgs(c *C) {
func (s *DBRecoverSuite) TestCommandUsage(c *C) {
// Test command usage information
cmd := makeCmdDBRecover()
c.Check(cmd.UsageLine, Equals, "recover")
c.Check(cmd.Short, Equals, "recover DB after crash")
c.Check(cmd.Long, Matches, "(?s).*Database recover does its' best to recover.*")
@@ -124,7 +124,7 @@ func (s *DBRecoverSuite) TestDBRecoverErrorHandling(c *C) {
expected: commander.ErrCommandError.Error(),
},
}
for _, tc := range testCases {
s.setupMockContext(c)
err := aptlyDBRecover(s.cmd, tc.args)
@@ -135,7 +135,7 @@ func (s *DBRecoverSuite) TestDBRecoverErrorHandling(c *C) {
func (s *DBRecoverSuite) TestCheckIntegrityFunction(c *C) {
// Test checkIntegrity function structure and patterns
s.setupMockContext(c)
// Test that checkIntegrity tries to call ForEach with checkRepo
// Since we don't have a real database, this will likely error, but tests the structure
err := checkIntegrity()
@@ -189,10 +189,10 @@ func (m *mockLocalRepoCollection) Update(repo *deb.LocalRepo) error {
func (s *DBRecoverSuite) TestCheckRepoFunction(c *C) {
// Test checkRepo function with mock data
s.setupMockContext(c)
// Create a mock repo
repo := &deb.LocalRepo{}
// Test that checkRepo handles the basic flow
// This will likely error due to missing collections, but tests the structure
err := checkRepo(repo)
@@ -201,20 +201,20 @@ func (s *DBRecoverSuite) TestCheckRepoFunction(c *C) {
func (s *DBRecoverSuite) TestCheckRepoErrorHandling(c *C) {
// Test error handling patterns in checkRepo
// Test error message formatting
repoName := "test-repo"
loadErr := errors.New("failed to load")
// Test error wrapping pattern used in checkRepo
err := fmt.Errorf("load complete repo %q: %s", repoName, loadErr)
c.Check(err.Error(), Equals, "load complete repo \"test-repo\": failed to load")
// Test another error pattern
danglingErr := errors.New("dangling reference error")
err = fmt.Errorf("find dangling references: %w", danglingErr)
c.Check(err.Error(), Equals, "find dangling references: dangling reference error")
// Test update error pattern
updateErr := errors.New("update failed")
err = fmt.Errorf("update repo: %w", updateErr)
@@ -223,22 +223,22 @@ func (s *DBRecoverSuite) TestCheckRepoErrorHandling(c *C) {
func (s *DBRecoverSuite) TestDanglingReferencesHandling(c *C) {
// Test dangling references handling patterns
// Mock dangling references structure
type mockDanglingRefs struct {
Refs []string
}
// Test with no dangling references
noDangling := &mockDanglingRefs{Refs: []string{}}
c.Check(len(noDangling.Refs), Equals, 0)
// Test with dangling references
withDangling := &mockDanglingRefs{
Refs: []string{"ref1", "ref2", "ref3"},
}
c.Check(len(withDangling.Refs), Equals, 3)
// Test processing dangling references
for i, ref := range withDangling.Refs {
c.Check(ref, Equals, fmt.Sprintf("ref%d", i+1))
@@ -247,18 +247,18 @@ func (s *DBRecoverSuite) TestDanglingReferencesHandling(c *C) {
func (s *DBRecoverSuite) TestProgressReporting(c *C) {
// Test progress reporting patterns used in db recover
type mockProgress struct {
messages []string
}
progress := &mockProgress{}
// Test progress messages used in the functions
progress.messages = append(progress.messages, "Recovering database...")
progress.messages = append(progress.messages, "Checking database integrity...")
progress.messages = append(progress.messages, "Removing dangling database reference \"ref1\"")
c.Check(len(progress.messages), Equals, 3)
c.Check(progress.messages[0], Equals, "Recovering database...")
c.Check(progress.messages[1], Equals, "Checking database integrity...")
@@ -267,7 +267,7 @@ func (s *DBRecoverSuite) TestProgressReporting(c *C) {
func (s *DBRecoverSuite) TestCollectionFactoryUsage(c *C) {
// Test collection factory usage patterns
factory := &mockCollectionFactory{
localRepoCollection: mockLocalRepoCollectionInterface{
repos: make(map[string]*deb.LocalRepo),
@@ -276,7 +276,7 @@ func (s *DBRecoverSuite) TestCollectionFactoryUsage(c *C) {
packages: []string{},
},
}
// Test factory usage
c.Check(factory.localRepoCollection, NotNil)
c.Check(factory.packageCollection, NotNil)
@@ -286,7 +286,7 @@ func (s *DBRecoverSuite) TestCollectionFactoryUsage(c *C) {
func (s *DBRecoverSuite) TestDBPathHandling(c *C) {
// Test database path handling patterns
s.setupMockContext(c)
// Test that context has DBPath method
// This will test the pattern used in goleveldb.RecoverDB(context.DBPath())
if context != nil {
@@ -298,13 +298,13 @@ func (s *DBRecoverSuite) TestDBPathHandling(c *C) {
func (s *DBRecoverSuite) TestRecoveryWorkflow(c *C) {
// Test the overall recovery workflow structure
type recoveryStep struct {
name string
description string
completed bool
}
// Simulate the recovery workflow
steps := []recoveryStep{
{
@@ -318,12 +318,12 @@ func (s *DBRecoverSuite) TestRecoveryWorkflow(c *C) {
completed: false,
},
}
// Simulate executing steps
for i := range steps {
steps[i].completed = true
}
// Verify all steps completed
allCompleted := true
for _, step := range steps {
@@ -332,7 +332,7 @@ func (s *DBRecoverSuite) TestRecoveryWorkflow(c *C) {
break
}
}
c.Check(allCompleted, Equals, true)
c.Check(len(steps), Equals, 2)
c.Check(steps[0].name, Equals, "recover_db")
@@ -341,16 +341,16 @@ func (s *DBRecoverSuite) TestRecoveryWorkflow(c *C) {
func (s *DBRecoverSuite) TestForEachRepoPattern(c *C) {
// Test the ForEach pattern used in checkIntegrity
// Mock repository list
repos := []*deb.LocalRepo{
// These would be real LocalRepo objects in practice
}
// Mock the ForEach pattern
processedRepos := 0
errors := []error{}
// Simulate ForEach with checkRepo
for _, repo := range repos {
err := checkRepo(repo)
@@ -359,7 +359,7 @@ func (s *DBRecoverSuite) TestForEachRepoPattern(c *C) {
errors = append(errors, err)
}
}
c.Check(processedRepos, Equals, len(repos))
// We expect errors since we're using mock data
c.Check(len(errors), Equals, len(repos))
@@ -367,19 +367,19 @@ func (s *DBRecoverSuite) TestForEachRepoPattern(c *C) {
func (s *DBRecoverSuite) TestRefListOperations(c *C) {
// Test reference list operations used in checkRepo
// Mock reference operations
totalRefs := 100
danglingCount := 5
remainingRefs := totalRefs - danglingCount
c.Check(remainingRefs, Equals, 95)
c.Check(danglingCount, Equals, 5)
// Test dangling reference removal pattern
danglingRefs := []string{"ref1", "ref2", "ref3", "ref4", "ref5"}
c.Check(len(danglingRefs), Equals, danglingCount)
for i, ref := range danglingRefs {
c.Check(ref, Equals, fmt.Sprintf("ref%d", i+1))
}
@@ -388,19 +388,19 @@ func (s *DBRecoverSuite) TestRefListOperations(c *C) {
func (s *DBRecoverSuite) TestCommandIntegration(c *C) {
// Test command integration and structure
cmd := makeCmdDBRecover()
// Verify command is properly constructed
c.Check(cmd.Run, Equals, aptlyDBRecover)
c.Check(cmd.UsageLine, Not(Equals), "")
c.Check(cmd.Short, Not(Equals), "")
c.Check(cmd.Long, Not(Equals), "")
// Test that command can be called (will error due to no real setup)
s.setupMockContext(c)
err := cmd.Run(cmd, []string{"invalid"})
c.Check(err, Equals, commander.ErrCommandError)
// Test with no args (expected case)
err = cmd.Run(cmd, []string{})
c.Check(err, NotNil) // Expected to fail with mock setup
}
}
+10 -10
View File
@@ -411,13 +411,13 @@ func (m *MockGraphProgress) Write(p []byte) (n int, err error) {
}
// Implement aptly.Progress interface
func (m *MockGraphProgress) Start() {}
func (m *MockGraphProgress) Shutdown() {}
func (m *MockGraphProgress) Flush() {}
func (m *MockGraphProgress) Start() {}
func (m *MockGraphProgress) Shutdown() {}
func (m *MockGraphProgress) Flush() {}
func (m *MockGraphProgress) InitBar(count int64, isBytes bool, barType aptly.BarType) {}
func (m *MockGraphProgress) ShutdownBar() {}
func (m *MockGraphProgress) AddBar(count int) {}
func (m *MockGraphProgress) SetBar(count int) {}
func (m *MockGraphProgress) ShutdownBar() {}
func (m *MockGraphProgress) AddBar(count int) {}
func (m *MockGraphProgress) SetBar(count int) {}
func (m *MockGraphProgress) Printf(msg string, a ...interface{}) {
formatted := fmt.Sprintf(msg, a...)
m.Messages = append(m.Messages, formatted)
@@ -439,8 +439,8 @@ type MockGraphContext struct {
mockGraph *MockGraph
}
func (m *MockGraphContext) Flags() *flag.FlagSet { return m.flags }
func (m *MockGraphContext) Progress() aptly.Progress { return m.progress }
func (m *MockGraphContext) Flags() *flag.FlagSet { return m.flags }
func (m *MockGraphContext) Progress() aptly.Progress { return m.progress }
func (m *MockGraphContext) NewCollectionFactory() *deb.CollectionFactory { return m.collectionFactory }
type MockGraph struct {
@@ -475,7 +475,7 @@ func (s *GraphSuite) TestAptlyGraphStdinPipeError(c *C) {
// This is harder to mock since exec.Command.StdinPipe() is not easily mockable
// We test this indirectly by ensuring our basic flow works
// The actual stdin pipe error would be rare and hard to reproduce in tests
// Clear PATH to ensure dot is not found (which triggers the error before stdin pipe)
originalPath := os.Getenv("PATH")
defer os.Setenv("PATH", originalPath)
@@ -484,4 +484,4 @@ func (s *GraphSuite) TestAptlyGraphStdinPipeError(c *C) {
err := aptlyGraph(s.cmd, []string{})
c.Check(err, NotNil)
c.Check(err.Error(), Matches, ".*unable to execute dot.*")
}
}
+30 -28
View File
@@ -317,13 +317,13 @@ func (m *MockMirrorCreateProgress) Write(p []byte) (n int, err error) {
}
// Implement aptly.Progress interface
func (m *MockMirrorCreateProgress) Start() {}
func (m *MockMirrorCreateProgress) Shutdown() {}
func (m *MockMirrorCreateProgress) Flush() {}
func (m *MockMirrorCreateProgress) Start() {}
func (m *MockMirrorCreateProgress) Shutdown() {}
func (m *MockMirrorCreateProgress) Flush() {}
func (m *MockMirrorCreateProgress) InitBar(count int64, isBytes bool, barType aptly.BarType) {}
func (m *MockMirrorCreateProgress) ShutdownBar() {}
func (m *MockMirrorCreateProgress) AddBar(count int) {}
func (m *MockMirrorCreateProgress) SetBar(count int) {}
func (m *MockMirrorCreateProgress) ShutdownBar() {}
func (m *MockMirrorCreateProgress) AddBar(count int) {}
func (m *MockMirrorCreateProgress) SetBar(count int) {}
func (m *MockMirrorCreateProgress) Printf(msg string, a ...interface{}) {
formatted := fmt.Sprintf(msg, a...)
m.Messages = append(m.Messages, formatted)
@@ -338,24 +338,26 @@ func (m *MockMirrorCreateProgress) PrintfStdErr(msg string, a ...interface{}) {
}
type MockMirrorCreateContext struct {
flags *flag.FlagSet
progress *MockMirrorCreateProgress
collectionFactory *deb.CollectionFactory
architectures []string
config *utils.ConfigStructure
downloader aptly.Downloader
ppaError bool
newRemoteRepoError bool
verifierError bool
fetchError bool
flags *flag.FlagSet
progress *MockMirrorCreateProgress
collectionFactory *deb.CollectionFactory
architectures []string
config *utils.ConfigStructure
downloader aptly.Downloader
ppaError bool
newRemoteRepoError bool
verifierError bool
fetchError bool
}
func (m *MockMirrorCreateContext) Flags() *flag.FlagSet { return m.flags }
func (m *MockMirrorCreateContext) Progress() aptly.Progress { return m.progress }
func (m *MockMirrorCreateContext) NewCollectionFactory() *deb.CollectionFactory { return m.collectionFactory }
func (m *MockMirrorCreateContext) ArchitecturesList() []string { return m.architectures }
func (m *MockMirrorCreateContext) Config() *utils.ConfigStructure { return m.config }
func (m *MockMirrorCreateContext) Downloader() aptly.Downloader { return m.downloader }
func (m *MockMirrorCreateContext) Flags() *flag.FlagSet { return m.flags }
func (m *MockMirrorCreateContext) Progress() aptly.Progress { return m.progress }
func (m *MockMirrorCreateContext) NewCollectionFactory() *deb.CollectionFactory {
return m.collectionFactory
}
func (m *MockMirrorCreateContext) ArchitecturesList() []string { return m.architectures }
func (m *MockMirrorCreateContext) Config() *utils.ConfigStructure { return m.config }
func (m *MockMirrorCreateContext) Downloader() aptly.Downloader { return m.downloader }
type MockMirrorCreateDownloader struct{}
@@ -366,8 +368,8 @@ func (m *MockMirrorCreateDownloader) Download(ctx stdcontext.Context, url string
func (m *MockMirrorCreateDownloader) DownloadWithChecksum(ctx stdcontext.Context, url string, destination string, expected *utils.ChecksumInfo, ignoreMismatch bool) error {
return nil
}
func (m *MockMirrorCreateDownloader) GetProgress() aptly.Progress {
return &MockMirrorCreateProgress{}
func (m *MockMirrorCreateDownloader) GetProgress() aptly.Progress {
return &MockMirrorCreateProgress{}
}
func (m *MockMirrorCreateDownloader) GetLength(ctx stdcontext.Context, url string) (int64, error) {
return 0, nil
@@ -452,18 +454,18 @@ func (s *MirrorCreateSuite) TestAptlyMirrorCreateFlagCombinations(c *C) {
// Test LookupOption functionality
func (s *MirrorCreateSuite) TestLookupOptionLogic(c *C) {
// Test the LookupOption function behavior
// Test with global config enabled, flag not set
s.mockContext.config.DownloadSourcePackages = true
result := LookupOption(s.mockContext.config.DownloadSourcePackages, &s.cmd.Flag, "with-sources")
c.Check(result, Equals, true)
// Test with global config disabled, flag explicitly set
s.mockContext.config.DownloadSourcePackages = false
s.cmd.Flag.Set("with-sources", "true")
result = LookupOption(s.mockContext.config.DownloadSourcePackages, &s.cmd.Flag, "with-sources")
c.Check(result, Equals, true)
// Reset
s.cmd.Flag.Set("with-sources", "false")
}
@@ -489,4 +491,4 @@ func (s *MirrorCreateSuite) TestArchitectureHandling(c *C) {
// Note: Removed fmt.Printf restoration
}
}
}
+17 -15
View File
@@ -291,13 +291,13 @@ func (m *MockMirrorEditProgress) Write(p []byte) (n int, err error) {
}
// Implement aptly.Progress interface
func (m *MockMirrorEditProgress) Start() {}
func (m *MockMirrorEditProgress) Shutdown() {}
func (m *MockMirrorEditProgress) Flush() {}
func (m *MockMirrorEditProgress) Start() {}
func (m *MockMirrorEditProgress) Shutdown() {}
func (m *MockMirrorEditProgress) Flush() {}
func (m *MockMirrorEditProgress) InitBar(count int64, isBytes bool, barType aptly.BarType) {}
func (m *MockMirrorEditProgress) ShutdownBar() {}
func (m *MockMirrorEditProgress) AddBar(count int) {}
func (m *MockMirrorEditProgress) SetBar(count int) {}
func (m *MockMirrorEditProgress) ShutdownBar() {}
func (m *MockMirrorEditProgress) AddBar(count int) {}
func (m *MockMirrorEditProgress) SetBar(count int) {}
func (m *MockMirrorEditProgress) Printf(msg string, a ...interface{}) {
formatted := fmt.Sprintf(msg, a...)
m.Messages = append(m.Messages, formatted)
@@ -322,12 +322,14 @@ type MockMirrorEditContext struct {
verifierError bool
}
func (m *MockMirrorEditContext) Flags() *flag.FlagSet { return m.flags }
func (m *MockMirrorEditContext) Progress() aptly.Progress { return m.progress }
func (m *MockMirrorEditContext) NewCollectionFactory() *deb.CollectionFactory { return m.collectionFactory }
func (m *MockMirrorEditContext) ArchitecturesList() []string { return m.architectures }
func (m *MockMirrorEditContext) Config() *utils.ConfigStructure { return m.config }
func (m *MockMirrorEditContext) Downloader() aptly.Downloader { return m.downloader }
func (m *MockMirrorEditContext) Flags() *flag.FlagSet { return m.flags }
func (m *MockMirrorEditContext) Progress() aptly.Progress { return m.progress }
func (m *MockMirrorEditContext) NewCollectionFactory() *deb.CollectionFactory {
return m.collectionFactory
}
func (m *MockMirrorEditContext) ArchitecturesList() []string { return m.architectures }
func (m *MockMirrorEditContext) Config() *utils.ConfigStructure { return m.config }
func (m *MockMirrorEditContext) Downloader() aptly.Downloader { return m.downloader }
func (m *MockMirrorEditContext) GlobalFlags() *flag.FlagSet {
globalFlags := flag.NewFlagSet("global", flag.ExitOnError)
@@ -349,8 +351,8 @@ func (m *MockDownloader) Download(ctx stdcontext.Context, url string, destinatio
func (m *MockDownloader) DownloadWithChecksum(ctx stdcontext.Context, url string, destination string, expected *utils.ChecksumInfo, ignoreMismatch bool) error {
return nil
}
func (m *MockDownloader) GetProgress() aptly.Progress {
return &MockMirrorEditProgress{}
func (m *MockDownloader) GetProgress() aptly.Progress {
return &MockMirrorEditProgress{}
}
func (m *MockDownloader) GetLength(ctx stdcontext.Context, url string) (int64, error) {
return 0, nil
@@ -485,4 +487,4 @@ func (s *MirrorEditSuite) TestAptlyMirrorEditArchitectureHandling(c *C) {
s.mockContext.architecturesChanged = false
// Note: Removed fmt.Printf restoration
}
}
}
+17 -15
View File
@@ -28,7 +28,7 @@ func (s *MirrorListSuite) SetUpTest(c *C) {
// Set up mock collections
s.collectionFactory = &deb.CollectionFactory{
// Note: Removed remoteRepoCollection field to fix compilation
// Note: Removed remoteRepoCollection field to fix compilation
}
// Set up mock context
@@ -249,10 +249,12 @@ type MockMirrorListContext struct {
collectionFactory *deb.CollectionFactory
}
func (m *MockMirrorListContext) Flags() *flag.FlagSet { return m.flags }
func (m *MockMirrorListContext) Progress() aptly.Progress { return m.progress }
func (m *MockMirrorListContext) NewCollectionFactory() *deb.CollectionFactory { return m.collectionFactory }
func (m *MockMirrorListContext) CloseDatabase() error { return nil }
func (m *MockMirrorListContext) Flags() *flag.FlagSet { return m.flags }
func (m *MockMirrorListContext) Progress() aptly.Progress { return m.progress }
func (m *MockMirrorListContext) NewCollectionFactory() *deb.CollectionFactory {
return m.collectionFactory
}
func (m *MockMirrorListContext) CloseDatabase() error { return nil }
type MockRemoteMirrorListCollection struct {
emptyCollection bool
@@ -289,7 +291,7 @@ func (m *MockRemoteMirrorListCollection) ForEach(handler func(*deb.RemoteRepo) e
Distribution: "stable",
Components: []string{"main"},
}
if err := handler(repo); err != nil {
return err
}
@@ -301,13 +303,13 @@ func (m *MockRemoteMirrorListCollection) ForEach(handler func(*deb.RemoteRepo) e
Distribution: "stable",
Components: []string{"main"},
}
// Create problematic repo for marshal error testing
if m.causeMarshalError {
// Create a structure that can't be marshaled
// Note: Removed cyclic reference as TestCyclicRef field doesn't exist
}
return handler(repo)
}
@@ -336,7 +338,7 @@ func (s *MirrorListSuite) TestSortingLogic(c *C) {
// Test string sorting
mirrors := []string{"z-mirror", "a-mirror", "m-mirror"}
sort.Strings(mirrors)
expected := []string{"a-mirror", "m-mirror", "z-mirror"}
c.Check(mirrors, DeepEquals, expected)
}
@@ -348,11 +350,11 @@ func (s *MirrorListSuite) TestMirrorSliceSorting(c *C) {
{Name: "a-mirror"},
{Name: "m-mirror"},
}
sort.Slice(repos, func(i, j int) bool {
return repos[i].Name < repos[j].Name
})
expectedOrder := []string{"a-mirror", "m-mirror", "z-mirror"}
for i, repo := range repos {
c.Check(repo.Name, Equals, expectedOrder[i])
@@ -366,7 +368,7 @@ func (s *MirrorListSuite) TestFormatStrings(c *C) {
ArchiveRoot: "http://example.com/debian",
Distribution: "stable",
}
// Test basic repo properties
c.Check(repo.Name, Equals, "test")
c.Check(repo.ArchiveRoot, Equals, "http://example.com/debian")
@@ -378,7 +380,7 @@ func (s *MirrorListSuite) TestEdgeCases(c *C) {
// Test with mirror that has minimal configuration
repo := &deb.RemoteRepo{Name: "simple-mirror"}
c.Check(repo.Name, Equals, "simple-mirror")
// Test basic repo properties
c.Check(len(repo.Name) > 0, Equals, true)
}
@@ -404,7 +406,7 @@ func (s *MirrorListSuite) TestFlagCombinations(c *C) {
for flag := range flags {
s.cmd.Flag.Set(flag, "false")
}
// Note: Removed complex output mocking to fix compilation
}
}
@@ -429,4 +431,4 @@ func (s *MirrorListSuite) TestMirrorConfigurations(c *C) {
// Basic test - function should complete successfully
// Note: Removed complex mocking to fix compilation
}
}
}
+8 -6
View File
@@ -234,7 +234,7 @@ func (s *MirrorShowSuite) TestAptlyMirrorShowJSONMarshalError(c *C) {
args := []string{"test-mirror"}
err := aptlyMirrorShow(s.cmd, args)
// Note: Actual marshal errors would be runtime dependent
_ = err // May or may not error depending on implementation
_ = err // May or may not error depending on implementation
s.cmd.Flag.Set("json", "false") // Reset flag
}
@@ -319,13 +319,15 @@ type MockMirrorShowContext struct {
collectionFactory *deb.CollectionFactory
}
func (m *MockMirrorShowContext) Flags() *flag.FlagSet { return m.flags }
func (m *MockMirrorShowContext) Progress() aptly.Progress { return m.progress }
func (m *MockMirrorShowContext) NewCollectionFactory() *deb.CollectionFactory { return m.collectionFactory }
func (m *MockMirrorShowContext) CloseDatabase() error { return nil }
func (m *MockMirrorShowContext) Flags() *flag.FlagSet { return m.flags }
func (m *MockMirrorShowContext) Progress() aptly.Progress { return m.progress }
func (m *MockMirrorShowContext) NewCollectionFactory() *deb.CollectionFactory {
return m.collectionFactory
}
func (m *MockMirrorShowContext) CloseDatabase() error { return nil }
// Note: Removed complex mock structures to fix compilation issues
// Tests are simplified to focus on basic command functionality
// Note: Removed method definitions on non-local types and global function overrides
// to fix compilation errors. Tests are simplified to focus on basic functionality.
// to fix compilation errors. Tests are simplified to focus on basic functionality.
+53 -53
View File
@@ -9,18 +9,18 @@ import (
"testing"
"github.com/aptly-dev/aptly/aptly"
ctx "github.com/aptly-dev/aptly/context"
"github.com/aptly-dev/aptly/deb"
"github.com/aptly-dev/aptly/pgp"
"github.com/aptly-dev/aptly/query"
ctx "github.com/aptly-dev/aptly/context"
"github.com/smira/commander"
"github.com/smira/flag"
. "gopkg.in/check.v1"
)
type MirrorUpdateSuite struct {
cmd *commander.Command
originalContext *ctx.AptlyContext
cmd *commander.Command
originalContext *ctx.AptlyContext
}
var _ = Suite(&MirrorUpdateSuite{})
@@ -44,7 +44,7 @@ func (s *MirrorUpdateSuite) setupMockContext(c *C) {
flags.Bool("ignore-signatures", false, "ignore signatures")
flags.Bool("ignore-checksums", false, "ignore checksums")
flags.Bool("skip-existing-packages", false, "skip existing")
err := InitContext(flags)
c.Assert(err, IsNil)
}
@@ -52,13 +52,13 @@ func (s *MirrorUpdateSuite) setupMockContext(c *C) {
func (s *MirrorUpdateSuite) TestMakeCmdMirrorUpdate(c *C) {
// Test that makeCmdMirrorUpdate creates a proper command
cmd := makeCmdMirrorUpdate()
c.Check(cmd, NotNil)
c.Check(cmd.Run, NotNil)
c.Check(cmd.UsageLine, Equals, "update <name>")
c.Check(cmd.Short, Equals, "update mirror")
c.Check(cmd.Long, Not(Equals), "")
// Check that all expected flags are present
c.Check(cmd.Flag.Lookup("force"), NotNil)
c.Check(cmd.Flag.Lookup("ignore-checksums"), NotNil)
@@ -73,7 +73,7 @@ func (s *MirrorUpdateSuite) TestMakeCmdMirrorUpdate(c *C) {
func (s *MirrorUpdateSuite) TestAptlyMirrorUpdateNoArgs(c *C) {
// Test aptlyMirrorUpdate with no arguments
s.setupMockContext(c)
err := aptlyMirrorUpdate(s.cmd, []string{})
c.Check(err, Equals, commander.ErrCommandError)
}
@@ -81,7 +81,7 @@ func (s *MirrorUpdateSuite) TestAptlyMirrorUpdateNoArgs(c *C) {
func (s *MirrorUpdateSuite) TestAptlyMirrorUpdateMultipleArgs(c *C) {
// Test aptlyMirrorUpdate with multiple arguments
s.setupMockContext(c)
err := aptlyMirrorUpdate(s.cmd, []string{"mirror1", "mirror2"})
c.Check(err, Equals, commander.ErrCommandError)
}
@@ -89,7 +89,7 @@ func (s *MirrorUpdateSuite) TestAptlyMirrorUpdateMultipleArgs(c *C) {
func (s *MirrorUpdateSuite) TestAptlyMirrorUpdateNonexistentMirror(c *C) {
// Test aptlyMirrorUpdate with nonexistent mirror
s.setupMockContext(c)
err := aptlyMirrorUpdate(s.cmd, []string{"nonexistent-mirror"})
c.Check(err, NotNil)
c.Check(err.Error(), Matches, "unable to update:.*")
@@ -166,32 +166,32 @@ func (m *mockRemoteRepo) FinalizeDownload(collectionFactory *deb.CollectionFacto
func (s *MirrorUpdateSuite) TestMirrorUpdateFlagParsing(c *C) {
// Test that command flags are properly parsed and used
cmd := makeCmdMirrorUpdate()
// Test default flag values
forceFlag := cmd.Flag.Lookup("force")
c.Check(forceFlag, NotNil)
c.Check(forceFlag.DefValue, Equals, "false")
ignoreChecksumsFlag := cmd.Flag.Lookup("ignore-checksums")
c.Check(ignoreChecksumsFlag, NotNil)
c.Check(ignoreChecksumsFlag.DefValue, Equals, "false")
ignoreSignaturesFlag := cmd.Flag.Lookup("ignore-signatures")
c.Check(ignoreSignaturesFlag, NotNil)
c.Check(ignoreSignaturesFlag.DefValue, Equals, "false")
skipExistingFlag := cmd.Flag.Lookup("skip-existing-packages")
c.Check(skipExistingFlag, NotNil)
c.Check(skipExistingFlag.DefValue, Equals, "false")
downloadLimitFlag := cmd.Flag.Lookup("download-limit")
c.Check(downloadLimitFlag, NotNil)
c.Check(downloadLimitFlag.DefValue, Equals, "0")
downloaderFlag := cmd.Flag.Lookup("downloader")
c.Check(downloaderFlag, NotNil)
c.Check(downloaderFlag.DefValue, Equals, "default")
maxTriesFlag := cmd.Flag.Lookup("max-tries")
c.Check(maxTriesFlag, NotNil)
c.Check(maxTriesFlag.DefValue, Equals, "1")
@@ -200,7 +200,7 @@ func (s *MirrorUpdateSuite) TestMirrorUpdateFlagParsing(c *C) {
func (s *MirrorUpdateSuite) TestMirrorUpdateCommandUsage(c *C) {
// Test command usage information
cmd := makeCmdMirrorUpdate()
c.Check(cmd.UsageLine, Equals, "update <name>")
c.Check(cmd.Short, Equals, "update mirror")
c.Check(cmd.Long, Matches, "(?s).*Updates remote mirror.*")
@@ -220,12 +220,12 @@ func (s *MirrorUpdateSuite) TestMirrorUpdateErrorHandling(c *C) {
expected: commander.ErrCommandError.Error(),
},
{
name: "too many arguments",
name: "too many arguments",
args: []string{"mirror1", "mirror2"},
expected: commander.ErrCommandError.Error(),
},
}
for _, tc := range testCases {
s.setupMockContext(c)
err := aptlyMirrorUpdate(s.cmd, tc.args)
@@ -241,7 +241,7 @@ func (s *MirrorUpdateSuite) TestMirrorUpdateErrorHandling(c *C) {
func (s *MirrorUpdateSuite) TestMirrorUpdateQueryParsing(c *C) {
// Test that query parsing works correctly
// This is an integration test for the query.Parse functionality used in the filter
testCases := []struct {
queryStr string
valid bool
@@ -252,7 +252,7 @@ func (s *MirrorUpdateSuite) TestMirrorUpdateQueryParsing(c *C) {
{"invalid query syntax %%%", false},
{"", false}, // empty query
}
for _, tc := range testCases {
_, err := query.Parse(tc.queryStr)
if tc.valid {
@@ -265,20 +265,20 @@ func (s *MirrorUpdateSuite) TestMirrorUpdateQueryParsing(c *C) {
func (s *MirrorUpdateSuite) TestMirrorUpdateConcurrencyStructures(c *C) {
// Test the concurrent download structures and patterns used in aptlyMirrorUpdate
// Test that we can create channels and sync structures like in the function
downloadQueue := make(chan int, 10)
var wg sync.WaitGroup
var errors []string
var errLock sync.Mutex
// Test the pushError function pattern
pushError := func(err error) {
errLock.Lock()
errors = append(errors, err.Error())
errLock.Unlock()
}
// Test concurrent error collection
numGoroutines := 5
for i := 0; i < numGoroutines; i++ {
@@ -288,10 +288,10 @@ func (s *MirrorUpdateSuite) TestMirrorUpdateConcurrencyStructures(c *C) {
pushError(fmt.Errorf("error from goroutine %d", id))
}(i)
}
wg.Wait()
close(downloadQueue)
// Verify error collection worked
c.Check(len(errors), Equals, numGoroutines)
for i, errMsg := range errors {
@@ -301,25 +301,25 @@ func (s *MirrorUpdateSuite) TestMirrorUpdateConcurrencyStructures(c *C) {
func (s *MirrorUpdateSuite) TestMirrorUpdateTempFileHandling(c *C) {
// Test temp file creation and cleanup patterns used in the download section
// Test temporary file creation pattern
tempFile, err := os.CreateTemp("", "test-download-file")
c.Check(err, IsNil)
tempPath := tempFile.Name()
tempFile.Close()
// Verify file exists
_, err = os.Stat(tempPath)
c.Check(err, IsNil)
// Test cleanup pattern (like in the defer function)
err = os.Remove(tempPath)
c.Check(err, IsNil)
// Verify file is gone
_, err = os.Stat(tempPath)
c.Check(os.IsNotExist(err), Equals, true)
// Test cleanup of nonexistent file (should not error)
err = os.Remove(tempPath)
c.Check(os.IsNotExist(err), Equals, true)
@@ -327,7 +327,7 @@ func (s *MirrorUpdateSuite) TestMirrorUpdateTempFileHandling(c *C) {
func (s *MirrorUpdateSuite) TestMirrorUpdateDownloadTaskStructure(c *C) {
// Test the download task structure and patterns
// Mock the PackageDownloadTask structure that would be used
tasks := []struct {
Done bool
@@ -346,11 +346,11 @@ func (s *MirrorUpdateSuite) TestMirrorUpdateDownloadTaskStructure(c *C) {
},
{
Done: true,
TempDownPath: "/tmp/package2.deb",
TempDownPath: "/tmp/package2.deb",
Additional: []interface{}{},
},
}
// Test processing pattern similar to the import loop
completedTasks := 0
for _, task := range tasks {
@@ -358,30 +358,30 @@ func (s *MirrorUpdateSuite) TestMirrorUpdateDownloadTaskStructure(c *C) {
completedTasks++
}
}
c.Check(completedTasks, Equals, 1)
c.Check(len(tasks), Equals, 2)
}
func (s *MirrorUpdateSuite) TestMirrorUpdateProgressReporting(c *C) {
// Test progress reporting patterns used in the function
// Test that we can create progress reporting structures
type mockProgress struct {
messages []string
barInit bool
barShut bool
}
progress := &mockProgress{}
// Test progress methods that would be called
progress.messages = append(progress.messages, "Downloading & parsing package files...")
progress.messages = append(progress.messages, "Applying filter...")
progress.messages = append(progress.messages, "Building download queue...")
progress.barInit = true
progress.barShut = true
c.Check(len(progress.messages), Equals, 3)
c.Check(progress.barInit, Equals, true)
c.Check(progress.barShut, Equals, true)
@@ -392,45 +392,45 @@ func (s *MirrorUpdateSuite) TestMirrorUpdateProgressReporting(c *C) {
func (s *MirrorUpdateSuite) TestMirrorUpdateDeferPatterns(c *C) {
// Test defer patterns used in the function
var cleanupCalled bool
var databaseReopened bool
func() {
defer func() {
// Simulate the cleanup defer
cleanupCalled = true
}()
defer func() {
// Simulate the database reopen defer
databaseReopened = true
}()
// Simulate function execution
}()
c.Check(cleanupCalled, Equals, true)
c.Check(databaseReopened, Equals, true)
}
func (s *MirrorUpdateSuite) TestMirrorUpdateContextCancellation(c *C) {
// Test context cancellation patterns used in the goroutines
// Create a simple context-like structure
done := make(chan struct{})
queue := make(chan int, 5)
// Put some items in queue
for i := 0; i < 3; i++ {
queue <- i
}
close(queue)
// Test the select pattern used in the download goroutines
processed := 0
cancelled := false
for {
select {
case item, ok := <-queue:
@@ -444,21 +444,21 @@ func (s *MirrorUpdateSuite) TestMirrorUpdateContextCancellation(c *C) {
goto finished
}
}
finished:
c.Check(processed, Equals, 3)
c.Check(cancelled, Equals, false)
// Test early cancellation
done2 := make(chan struct{})
close(done2) // Cancel immediately
select {
case <-done2:
cancelled = true
default:
cancelled = false
}
c.Check(cancelled, Equals, true)
}
}
+29 -27
View File
@@ -132,7 +132,7 @@ func (s *PackageShowSuite) TestAptlyPackageShowWithFilesError(c *C) {
args := []string{"nginx"}
err := aptlyPackageShow(s.cmd, args)
// Note: Actual error handling depends on real implementation
_ = err // May or may not error depending on implementation
_ = err // May or may not error depending on implementation
s.cmd.Flag.Set("with-files", "false") // Reset flag
}
@@ -155,7 +155,7 @@ func (s *PackageShowSuite) TestAptlyPackageShowWithReferencesRemoteError(c *C) {
args := []string{"nginx"}
err := aptlyPackageShow(s.cmd, args)
// Note: Actual error handling depends on real implementation
_ = err // May or may not error depending on implementation
_ = err // May or may not error depending on implementation
s.cmd.Flag.Set("with-references", "false") // Reset flag
}
@@ -166,7 +166,7 @@ func (s *PackageShowSuite) TestAptlyPackageShowWithReferencesLocalError(c *C) {
args := []string{"nginx"}
err := aptlyPackageShow(s.cmd, args)
// Note: Actual error handling depends on real implementation
_ = err // May or may not error depending on implementation
_ = err // May or may not error depending on implementation
s.cmd.Flag.Set("with-references", "false") // Reset flag
}
@@ -177,7 +177,7 @@ func (s *PackageShowSuite) TestAptlyPackageShowWithReferencesSnapshotError(c *C)
args := []string{"nginx"}
err := aptlyPackageShow(s.cmd, args)
// Note: Actual error handling depends on real implementation
_ = err // May or may not error depending on implementation
_ = err // May or may not error depending on implementation
s.cmd.Flag.Set("with-references", "false") // Reset flag
}
@@ -188,7 +188,7 @@ func (s *PackageShowSuite) TestAptlyPackageShowWithReferencesLoadError(c *C) {
args := []string{"nginx"}
err := aptlyPackageShow(s.cmd, args)
// Note: Actual error handling depends on real implementation
_ = err // May or may not error depending on implementation
_ = err // May or may not error depending on implementation
s.cmd.Flag.Set("with-references", "false") // Reset flag
}
@@ -225,10 +225,10 @@ func (s *PackageShowSuite) TestAptlyPackageShowPackageForEachError(c *C) {
func (s *PackageShowSuite) TestPrintReferencesToBasic(c *C) {
// Test printReferencesTo function directly - simplified test
pkg := &deb.Package{Name: "test-package"}
// Note: Function call depends on real implementation
// Basic test would check if printReferencesTo exists and doesn't panic
_ = pkg // Use variable to avoid unused warning
_ = pkg // Use variable to avoid unused warning
c.Check(true, Equals, true) // Placeholder assertion
}
@@ -305,16 +305,18 @@ type MockPackageShowContext struct {
packagePool aptly.PackagePool
}
func (m *MockPackageShowContext) Flags() *flag.FlagSet { return m.flags }
func (m *MockPackageShowContext) Progress() aptly.Progress { return m.progress }
func (m *MockPackageShowContext) NewCollectionFactory() *deb.CollectionFactory { return m.collectionFactory }
func (m *MockPackageShowContext) PackagePool() aptly.PackagePool { return m.packagePool }
func (m *MockPackageShowContext) CloseDatabase() error { return nil }
func (m *MockPackageShowContext) Flags() *flag.FlagSet { return m.flags }
func (m *MockPackageShowContext) Progress() aptly.Progress { return m.progress }
func (m *MockPackageShowContext) NewCollectionFactory() *deb.CollectionFactory {
return m.collectionFactory
}
func (m *MockPackageShowContext) PackagePool() aptly.PackagePool { return m.packagePool }
func (m *MockPackageShowContext) CloseDatabase() error { return nil }
type MockRemotePackageShowCollection struct {
shouldErrorForEach bool
shouldErrorLoadComplete bool
forEachCalled bool
shouldErrorForEach bool
shouldErrorLoadComplete bool
forEachCalled bool
}
func (m *MockRemotePackageShowCollection) ForEach(handler func(*deb.RemoteRepo) error) error {
@@ -326,7 +328,7 @@ func (m *MockRemotePackageShowCollection) ForEach(handler func(*deb.RemoteRepo)
// Create mock repo - simplified
repo := &deb.RemoteRepo{Name: "test-remote-repo"}
// Note: Removed access to unexported fields
return handler(repo)
}
@@ -338,9 +340,9 @@ func (m *MockRemotePackageShowCollection) LoadComplete(repo *deb.RemoteRepo) err
}
type MockLocalPackageShowCollection struct {
shouldErrorForEach bool
shouldErrorLoadComplete bool
forEachCalled bool
shouldErrorForEach bool
shouldErrorLoadComplete bool
forEachCalled bool
}
func (m *MockLocalPackageShowCollection) ForEach(handler func(*deb.LocalRepo) error) error {
@@ -352,7 +354,7 @@ func (m *MockLocalPackageShowCollection) ForEach(handler func(*deb.LocalRepo) er
// Create mock repo - simplified
repo := &deb.LocalRepo{Name: "test-local-repo"}
// Note: Removed access to unexported fields
return handler(repo)
}
@@ -364,9 +366,9 @@ func (m *MockLocalPackageShowCollection) LoadComplete(repo *deb.LocalRepo) error
}
type MockSnapshotPackageShowCollection struct {
shouldErrorForEach bool
shouldErrorLoadComplete bool
forEachCalled bool
shouldErrorForEach bool
shouldErrorLoadComplete bool
forEachCalled bool
}
func (m *MockSnapshotPackageShowCollection) ForEach(handler func(*deb.Snapshot) error) error {
@@ -378,7 +380,7 @@ func (m *MockSnapshotPackageShowCollection) ForEach(handler func(*deb.Snapshot)
// Create mock snapshot - simplified
snapshot := &deb.Snapshot{Name: "test-snapshot"}
// Note: Removed access to unexported fields
return handler(snapshot)
}
@@ -397,11 +399,11 @@ type MockPackageQueryCollection struct {
func (m *MockPackageQueryCollection) Query(query deb.PackageQuery) *deb.PackageList {
m.queryCalled = true
// Return a simple mock package list
packageList := &deb.PackageList{}
// Note: Simplified to avoid method assignment issues
return packageList
}
@@ -469,4 +471,4 @@ func (m *MockLocalPackageShowPool) FullPath(relativePath string) string {
}
// Note: Removed method definitions on non-local types and global function overrides
// to fix compilation errors. Tests are simplified to focus on basic functionality.
// to fix compilation errors. Tests are simplified to focus on basic functionality.
+18 -16
View File
@@ -195,7 +195,7 @@ func (s *PublishListSuite) TestAptlyPublishListSorting(c *C) {
foundMessages = append(foundMessages, msg)
}
}
c.Check(len(foundMessages) >= 3, Equals, true)
// Should be in alphabetical order
c.Check(strings.Contains(foundMessages[0], "a-repo"), Equals, true)
@@ -305,19 +305,21 @@ type MockPublishListContext struct {
collectionFactory *deb.CollectionFactory
}
func (m *MockPublishListContext) Flags() *flag.FlagSet { return m.flags }
func (m *MockPublishListContext) Progress() aptly.Progress { return m.progress }
func (m *MockPublishListContext) NewCollectionFactory() *deb.CollectionFactory { return m.collectionFactory }
func (m *MockPublishListContext) CloseDatabase() error { return nil }
func (m *MockPublishListContext) Flags() *flag.FlagSet { return m.flags }
func (m *MockPublishListContext) Progress() aptly.Progress { return m.progress }
func (m *MockPublishListContext) NewCollectionFactory() *deb.CollectionFactory {
return m.collectionFactory
}
func (m *MockPublishListContext) CloseDatabase() error { return nil }
type MockPublishedListRepoCollection struct {
emptyCollection bool
shouldErrorForEach bool
shouldErrorLoadShallow bool
shouldErrorLoadComplete bool
causeMarshalError bool
multipleRepos bool
repoNames []string
emptyCollection bool
shouldErrorForEach bool
shouldErrorLoadShallow bool
shouldErrorLoadComplete bool
causeMarshalError bool
multipleRepos bool
repoNames []string
}
func (m *MockPublishedListRepoCollection) Len() int {
@@ -356,12 +358,12 @@ func (m *MockPublishedListRepoCollection) ForEach(handler func(*deb.PublishedRep
Prefix: "ppa",
// Note: Removed components field as it's not exported
}
// Create problematic repo for marshal error testing
if m.causeMarshalError {
// Note: Removed TestCyclicRef as it doesn't exist
}
return handler(repo)
}
@@ -408,7 +410,7 @@ func (s *PublishListSuite) TestStderrOutput(c *C) {
err := aptlyPublishList(s.cmd, []string{})
c.Check(err, NotNil)
// The error should propagate from LoadShallow
c.Check(err.Error(), Matches, ".*mock load shallow error.*")
}
}
+19 -17
View File
@@ -49,7 +49,7 @@ func (s *PublishShowSuite) TestMakeCmdPublishShow(c *C) {
func (s *PublishShowSuite) TestPublishShowFlags(c *C) {
err := s.cmd.Flag.Set("type", "local")
c.Check(err, IsNil)
err = s.cmd.Flag.Set("distribution", "stable")
c.Check(err, IsNil)
}
@@ -58,18 +58,18 @@ func (s *PublishShowSuite) TestPublishShowFlags(c *C) {
type MockPublishShowProgress struct{}
func (m *MockPublishShowProgress) Printf(msg string, a ...interface{}) {}
func (m *MockPublishShowProgress) ColoredPrintf(msg string, a ...interface{}) {}
func (m *MockPublishShowProgress) PrintfStdErr(msg string, a ...interface{}) {}
func (m *MockPublishShowProgress) Flush() {}
func (m *MockPublishShowProgress) Start() {}
func (m *MockPublishShowProgress) Shutdown() {}
func (m *MockPublishShowProgress) Printf(msg string, a ...interface{}) {}
func (m *MockPublishShowProgress) ColoredPrintf(msg string, a ...interface{}) {}
func (m *MockPublishShowProgress) PrintfStdErr(msg string, a ...interface{}) {}
func (m *MockPublishShowProgress) Flush() {}
func (m *MockPublishShowProgress) Start() {}
func (m *MockPublishShowProgress) Shutdown() {}
func (m *MockPublishShowProgress) InitBar(count int64, isBytes bool, barType aptly.BarType) {}
func (m *MockPublishShowProgress) ShutdownBar() {}
func (m *MockPublishShowProgress) AddBar(count int) {}
func (m *MockPublishShowProgress) SetBar(count int) {}
func (m *MockPublishShowProgress) PrintfBar(msg string, a ...interface{}) {}
func (m *MockPublishShowProgress) Write(p []byte) (n int, err error) { return len(p), nil }
func (m *MockPublishShowProgress) ShutdownBar() {}
func (m *MockPublishShowProgress) AddBar(count int) {}
func (m *MockPublishShowProgress) SetBar(count int) {}
func (m *MockPublishShowProgress) PrintfBar(msg string, a ...interface{}) {}
func (m *MockPublishShowProgress) Write(p []byte) (n int, err error) { return len(p), nil }
type MockPublishShowContext struct {
flags *flag.FlagSet
@@ -77,9 +77,11 @@ type MockPublishShowContext struct {
collectionFactory *deb.CollectionFactory
}
func (m *MockPublishShowContext) Flags() *flag.FlagSet { return m.flags }
func (m *MockPublishShowContext) Progress() aptly.Progress { return m.progress }
func (m *MockPublishShowContext) NewCollectionFactory() *deb.CollectionFactory { return m.collectionFactory }
func (m *MockPublishShowContext) Config() *utils.ConfigStructure { return &utils.ConfigStructure{} }
func (m *MockPublishShowContext) Flags() *flag.FlagSet { return m.flags }
func (m *MockPublishShowContext) Progress() aptly.Progress { return m.progress }
func (m *MockPublishShowContext) NewCollectionFactory() *deb.CollectionFactory {
return m.collectionFactory
}
func (m *MockPublishShowContext) Config() *utils.ConfigStructure { return &utils.ConfigStructure{} }
// Note: Complex integration tests have been simplified for compilation compatibility.
// Note: Complex integration tests have been simplified for compilation compatibility.
+28 -26
View File
@@ -24,7 +24,7 @@ var _ = Suite(&PublishSnapshotSuite{})
func (s *PublishSnapshotSuite) SetUpTest(c *C) {
s.cmd = makeCmdPublishSnapshot()
s.mockProgress = &MockPublishProgress{}
// Set up mock collections - simplified
s.collectionFactory = deb.NewCollectionFactory(nil)
@@ -138,7 +138,7 @@ func (s *PublishSnapshotSuite) TestAptlyPublishMultiComponent(c *C) {
func (s *PublishSnapshotSuite) TestAptlyPublishInvalidArguments(c *C) {
// Test with invalid number of arguments - simplified test
s.cmd.Flag.Set("component", "main,contrib")
// Too few arguments
args := []string{"only-one-snapshot"}
err := aptlyPublishSnapshotOrRepo(s.cmd, args)
@@ -350,7 +350,7 @@ func (s *PublishSnapshotSuite) TestAptlyPublishOutputFormatting(c *C) {
func (s *PublishSnapshotSuite) TestAptlyPublishSourceArchitecture(c *C) {
// Test publishing with source architecture - simplified test
s.mockContext.architecturesList = []string{"amd64", "source"}
args := []string{"test-snapshot"}
err := aptlyPublishSnapshotOrRepo(s.cmd, args)
// Note: Actual behavior depends on real implementation
@@ -426,26 +426,28 @@ func (m *MockPublishProgress) Write(data []byte) (int, error) {
}
type MockPublishContext struct {
flags *flag.FlagSet
progress *MockPublishProgress
collectionFactory *deb.CollectionFactory
architecturesList []string
packagePool aptly.PackagePool
config *MockPublishConfig
publishedStorage aptly.PublishedStorage
skelPath string
flags *flag.FlagSet
progress *MockPublishProgress
collectionFactory *deb.CollectionFactory
architecturesList []string
packagePool aptly.PackagePool
config *MockPublishConfig
publishedStorage aptly.PublishedStorage
skelPath string
shouldErrorNewPublishedRepo bool
shouldErrorGetSigner bool
shouldErrorPublish bool
shouldErrorGetSigner bool
shouldErrorPublish bool
}
func (m *MockPublishContext) Flags() *flag.FlagSet { return m.flags }
func (m *MockPublishContext) Progress() aptly.Progress { return m.progress }
func (m *MockPublishContext) NewCollectionFactory() *deb.CollectionFactory { return m.collectionFactory }
func (m *MockPublishContext) ArchitecturesList() []string { return m.architecturesList }
func (m *MockPublishContext) PackagePool() aptly.PackagePool { return m.packagePool }
func (m *MockPublishContext) Config() *utils.ConfigStructure { return &utils.ConfigStructure{} }
func (m *MockPublishContext) SkelPath() string { return m.skelPath }
func (m *MockPublishContext) Flags() *flag.FlagSet { return m.flags }
func (m *MockPublishContext) Progress() aptly.Progress { return m.progress }
func (m *MockPublishContext) NewCollectionFactory() *deb.CollectionFactory {
return m.collectionFactory
}
func (m *MockPublishContext) ArchitecturesList() []string { return m.architecturesList }
func (m *MockPublishContext) PackagePool() aptly.PackagePool { return m.packagePool }
func (m *MockPublishContext) Config() *utils.ConfigStructure { return &utils.ConfigStructure{} }
func (m *MockPublishContext) SkelPath() string { return m.skelPath }
func (m *MockPublishContext) GetPublishedStorage(name string) aptly.PublishedStorage {
return m.publishedStorage
@@ -491,8 +493,8 @@ func (m *MockPublishPackagePool) LegacyPath(filename string, checksums *utils.Ch
}
type MockSnapshotPublishCollection struct {
shouldErrorByName bool
shouldErrorLoadComplete bool
shouldErrorByName bool
shouldErrorLoadComplete bool
emptySnapshots bool
}
@@ -514,7 +516,7 @@ func (m *MockSnapshotPublishCollection) LoadComplete(snapshot *deb.Snapshot) err
type MockLocalRepoPublishCollection struct {
shouldErrorByName bool
shouldErrorLoadComplete bool
emptyRepos bool
emptyRepos bool
}
func (m *MockLocalRepoPublishCollection) ByName(name string) (*deb.LocalRepo, error) {
@@ -533,8 +535,8 @@ func (m *MockLocalRepoPublishCollection) LoadComplete(repo *deb.LocalRepo) error
}
type MockPublishedRepoPublishCollection struct {
hasDuplicate bool
shouldErrorAdd bool
hasDuplicate bool
shouldErrorAdd bool
}
func (m *MockPublishedRepoPublishCollection) CheckDuplicate(published *deb.PublishedRepo) *deb.PublishedRepo {
@@ -611,4 +613,4 @@ func (m *MockPublishedStorage) ReadLink(path string) (string, error) {
func (m *MockPublishedStorage) SymLink(src, dst string) error {
return nil
}
}
+9 -10
View File
@@ -33,7 +33,7 @@ func (s *PublishSourceAddSuite) setupMockContext(c *C) {
flags := flag.NewFlagSet("test", flag.ContinueOnError)
flags.String("prefix", ".", "publishing prefix")
flags.String("component", "", "component names to add")
err := InitContext(flags)
c.Assert(err, IsNil)
}
@@ -59,7 +59,7 @@ func (s *PublishSourceAddSuite) TestMakeCmdPublishSourceAdd(c *C) {
func (s *PublishSourceAddSuite) TestAptlyPublishSourceAddInvalidArgs(c *C) {
// Test with insufficient arguments
s.setupMockContext(c)
err := aptlyPublishSourceAdd(s.cmd, []string{})
c.Check(err, Equals, commander.ErrCommandError)
@@ -70,7 +70,7 @@ func (s *PublishSourceAddSuite) TestAptlyPublishSourceAddInvalidArgs(c *C) {
func (s *PublishSourceAddSuite) TestAptlyPublishSourceAddBasic(c *C) {
// Test basic source addition
s.setupMockContext(c)
context.Flags().Set("component", "contrib")
args := []string{"stable", "contrib-snapshot"}
@@ -82,7 +82,7 @@ func (s *PublishSourceAddSuite) TestAptlyPublishSourceAddBasic(c *C) {
func (s *PublishSourceAddSuite) TestAptlyPublishSourceAddMismatchComponents(c *C) {
// Test with mismatched number of components and sources
s.setupMockContext(c)
context.Flags().Set("component", "main,contrib")
args := []string{"stable", "single-source"} // 2 components, 1 source
@@ -94,7 +94,7 @@ func (s *PublishSourceAddSuite) TestAptlyPublishSourceAddMismatchComponents(c *C
func (s *PublishSourceAddSuite) TestAptlyPublishSourceAddMultipleComponents(c *C) {
// Test with multiple components
s.setupMockContext(c)
context.Flags().Set("component", "main,contrib,non-free")
args := []string{"stable", "main-snapshot", "contrib-snapshot", "non-free-snapshot"}
@@ -106,7 +106,7 @@ func (s *PublishSourceAddSuite) TestAptlyPublishSourceAddMultipleComponents(c *C
func (s *PublishSourceAddSuite) TestAptlyPublishSourceAddWithPrefix(c *C) {
// Test with custom prefix
s.setupMockContext(c)
context.Flags().Set("prefix", "ppa")
context.Flags().Set("component", "contrib")
args := []string{"stable", "contrib-snapshot"}
@@ -119,7 +119,7 @@ func (s *PublishSourceAddSuite) TestAptlyPublishSourceAddWithPrefix(c *C) {
func (s *PublishSourceAddSuite) TestAptlyPublishSourceAddWithStorage(c *C) {
// Test with storage endpoint
s.setupMockContext(c)
context.Flags().Set("prefix", "s3:bucket")
context.Flags().Set("component", "contrib")
args := []string{"stable", "contrib-snapshot"}
@@ -132,7 +132,7 @@ func (s *PublishSourceAddSuite) TestAptlyPublishSourceAddWithStorage(c *C) {
func (s *PublishSourceAddSuite) TestAptlyPublishSourceAddRepoNotFound(c *C) {
// Test with non-existent published repository
s.setupMockContext(c)
context.Flags().Set("component", "contrib")
args := []string{"nonexistent-dist", "contrib-snapshot"}
@@ -144,7 +144,7 @@ func (s *PublishSourceAddSuite) TestAptlyPublishSourceAddRepoNotFound(c *C) {
func (s *PublishSourceAddSuite) TestAptlyPublishSourceAddEmptyComponent(c *C) {
// Test with empty component flag
s.setupMockContext(c)
context.Flags().Set("component", "")
args := []string{"stable", "contrib-snapshot"}
@@ -152,4 +152,3 @@ func (s *PublishSourceAddSuite) TestAptlyPublishSourceAddEmptyComponent(c *C) {
c.Check(err, NotNil)
c.Check(err.Error(), Matches, ".*mismatch in number of components.*")
}
+16 -14
View File
@@ -181,7 +181,7 @@ func (s *PublishSourceListSuite) TestAptlyPublishSourceListPrefixParsing(c *C) {
func (s *PublishSourceListSuite) TestAptlyPublishSourceListFormatToggle(c *C) {
// Test switching between text and JSON formats
formats := []struct {
jsonFlag bool
jsonFlag bool
description string
}{
{false, "text format"},
@@ -282,16 +282,16 @@ func (m *MockPublishSourceListProgress) Printf(msg string, a ...interface{}) {
m.Messages = append(m.Messages, formatted)
}
func (m *MockPublishSourceListProgress) AddBar(count int) {}
func (m *MockPublishSourceListProgress) Flush() {}
func (m *MockPublishSourceListProgress) AddBar(count int) {}
func (m *MockPublishSourceListProgress) Flush() {}
func (m *MockPublishSourceListProgress) InitBar(total int64, colored bool, barType aptly.BarType) {}
func (m *MockPublishSourceListProgress) PrintfStdErr(msg string, a ...interface{}) {}
func (m *MockPublishSourceListProgress) SetBar(count int) {}
func (m *MockPublishSourceListProgress) Shutdown() {}
func (m *MockPublishSourceListProgress) ShutdownBar() {}
func (m *MockPublishSourceListProgress) Start() {}
func (m *MockPublishSourceListProgress) Write(data []byte) (int, error) { return len(data), nil }
func (m *MockPublishSourceListProgress) ColoredPrintf(msg string, a ...interface{}) {}
func (m *MockPublishSourceListProgress) PrintfStdErr(msg string, a ...interface{}) {}
func (m *MockPublishSourceListProgress) SetBar(count int) {}
func (m *MockPublishSourceListProgress) Shutdown() {}
func (m *MockPublishSourceListProgress) ShutdownBar() {}
func (m *MockPublishSourceListProgress) Start() {}
func (m *MockPublishSourceListProgress) Write(data []byte) (int, error) { return len(data), nil }
func (m *MockPublishSourceListProgress) ColoredPrintf(msg string, a ...interface{}) {}
type MockPublishSourceListContext struct {
flags *flag.FlagSet
@@ -299,9 +299,11 @@ type MockPublishSourceListContext struct {
collectionFactory *deb.CollectionFactory
}
func (m *MockPublishSourceListContext) Flags() *flag.FlagSet { return m.flags }
func (m *MockPublishSourceListContext) Progress() aptly.Progress { return m.progress }
func (m *MockPublishSourceListContext) NewCollectionFactory() *deb.CollectionFactory { return m.collectionFactory }
func (m *MockPublishSourceListContext) Flags() *flag.FlagSet { return m.flags }
func (m *MockPublishSourceListContext) Progress() aptly.Progress { return m.progress }
func (m *MockPublishSourceListContext) NewCollectionFactory() *deb.CollectionFactory {
return m.collectionFactory
}
type MockPublishedSourceListRepoCollection struct {
shouldErrorByStoragePrefixDistribution bool
@@ -536,4 +538,4 @@ func (s *PublishSourceListSuite) TestJSONMarshalError(c *C) {
c.Check(err.Error(), Matches, ".*unable to list.*")
}
// Note: Removed mock revision type to simplify compilation
// Note: Removed mock revision type to simplify compilation
+16 -13
View File
@@ -252,7 +252,7 @@ func (s *PublishSourceReplaceSuite) TestAptlyPublishSourceReplaceComponentValida
{"main,contrib", []string{"main-source", "contrib-source"}, false},
{"main,contrib,non-free", []string{"main-source", "contrib-source", "non-free-source"}, false},
{"main,contrib", []string{"single-source"}, true}, // Mismatch
{"", []string{"source"}, true}, // Empty component
{"", []string{"source"}, true}, // Empty component
}
for _, test := range componentTests {
@@ -393,14 +393,15 @@ func (m *MockPublishSourceReplaceProgress) Printf(msg string, a ...interface{})
}
func (m *MockPublishSourceReplaceProgress) AddBar(count int) {}
func (m *MockPublishSourceReplaceProgress) Flush() {}
func (m *MockPublishSourceReplaceProgress) InitBar(total int64, colored bool, barType aptly.BarType) {}
func (m *MockPublishSourceReplaceProgress) PrintfStdErr(msg string, a ...interface{}) {}
func (m *MockPublishSourceReplaceProgress) SetBar(count int) {}
func (m *MockPublishSourceReplaceProgress) Shutdown() {}
func (m *MockPublishSourceReplaceProgress) ShutdownBar() {}
func (m *MockPublishSourceReplaceProgress) Start() {}
func (m *MockPublishSourceReplaceProgress) Write(data []byte) (int, error) { return len(data), nil }
func (m *MockPublishSourceReplaceProgress) Flush() {}
func (m *MockPublishSourceReplaceProgress) InitBar(total int64, colored bool, barType aptly.BarType) {
}
func (m *MockPublishSourceReplaceProgress) PrintfStdErr(msg string, a ...interface{}) {}
func (m *MockPublishSourceReplaceProgress) SetBar(count int) {}
func (m *MockPublishSourceReplaceProgress) Shutdown() {}
func (m *MockPublishSourceReplaceProgress) ShutdownBar() {}
func (m *MockPublishSourceReplaceProgress) Start() {}
func (m *MockPublishSourceReplaceProgress) Write(data []byte) (int, error) { return len(data), nil }
func (m *MockPublishSourceReplaceProgress) ColoredPrintf(msg string, a ...interface{}) {}
type MockPublishSourceReplaceContext struct {
@@ -409,9 +410,11 @@ type MockPublishSourceReplaceContext struct {
collectionFactory *deb.CollectionFactory
}
func (m *MockPublishSourceReplaceContext) Flags() *flag.FlagSet { return m.flags }
func (m *MockPublishSourceReplaceContext) Progress() aptly.Progress { return m.progress }
func (m *MockPublishSourceReplaceContext) NewCollectionFactory() *deb.CollectionFactory { return m.collectionFactory }
func (m *MockPublishSourceReplaceContext) Flags() *flag.FlagSet { return m.flags }
func (m *MockPublishSourceReplaceContext) Progress() aptly.Progress { return m.progress }
func (m *MockPublishSourceReplaceContext) NewCollectionFactory() *deb.CollectionFactory {
return m.collectionFactory
}
type MockPublishedSourceReplaceRepoCollection struct {
shouldErrorByStoragePrefixDistribution bool
@@ -591,4 +594,4 @@ func (s *PublishSourceReplaceSuite) TestSpecialCharactersInComponents(c *C) {
}
}
c.Check(addingCount, Equals, 3)
}
}
+16 -14
View File
@@ -257,7 +257,7 @@ func (s *PublishSourceUpdateSuite) TestAptlyPublishSourceUpdateComponentValidati
{"main,contrib", []string{"main-source", "contrib-source"}, false},
{"main,contrib,non-free", []string{"main-source", "contrib-source", "non-free-source"}, false},
{"main,contrib", []string{"single-source"}, true}, // Mismatch
{"", []string{"source"}, true}, // Empty component
{"", []string{"source"}, true}, // Empty component
}
for _, test := range componentTests {
@@ -390,16 +390,16 @@ func (m *MockPublishSourceUpdateProgress) Printf(msg string, a ...interface{}) {
m.Messages = append(m.Messages, formatted)
}
func (m *MockPublishSourceUpdateProgress) AddBar(count int) {}
func (m *MockPublishSourceUpdateProgress) Flush() {}
func (m *MockPublishSourceUpdateProgress) AddBar(count int) {}
func (m *MockPublishSourceUpdateProgress) Flush() {}
func (m *MockPublishSourceUpdateProgress) InitBar(total int64, colored bool, barType aptly.BarType) {}
func (m *MockPublishSourceUpdateProgress) PrintfStdErr(msg string, a ...interface{}) {}
func (m *MockPublishSourceUpdateProgress) SetBar(count int) {}
func (m *MockPublishSourceUpdateProgress) Shutdown() {}
func (m *MockPublishSourceUpdateProgress) ShutdownBar() {}
func (m *MockPublishSourceUpdateProgress) Start() {}
func (m *MockPublishSourceUpdateProgress) Write(data []byte) (int, error) { return len(data), nil }
func (m *MockPublishSourceUpdateProgress) ColoredPrintf(msg string, a ...interface{}) {}
func (m *MockPublishSourceUpdateProgress) PrintfStdErr(msg string, a ...interface{}) {}
func (m *MockPublishSourceUpdateProgress) SetBar(count int) {}
func (m *MockPublishSourceUpdateProgress) Shutdown() {}
func (m *MockPublishSourceUpdateProgress) ShutdownBar() {}
func (m *MockPublishSourceUpdateProgress) Start() {}
func (m *MockPublishSourceUpdateProgress) Write(data []byte) (int, error) { return len(data), nil }
func (m *MockPublishSourceUpdateProgress) ColoredPrintf(msg string, a ...interface{}) {}
type MockPublishSourceUpdateContext struct {
flags *flag.FlagSet
@@ -407,9 +407,11 @@ type MockPublishSourceUpdateContext struct {
collectionFactory *deb.CollectionFactory
}
func (m *MockPublishSourceUpdateContext) Flags() *flag.FlagSet { return m.flags }
func (m *MockPublishSourceUpdateContext) Progress() aptly.Progress { return m.progress }
func (m *MockPublishSourceUpdateContext) NewCollectionFactory() *deb.CollectionFactory { return m.collectionFactory }
func (m *MockPublishSourceUpdateContext) Flags() *flag.FlagSet { return m.flags }
func (m *MockPublishSourceUpdateContext) Progress() aptly.Progress { return m.progress }
func (m *MockPublishSourceUpdateContext) NewCollectionFactory() *deb.CollectionFactory {
return m.collectionFactory
}
type MockPublishedSourceUpdateRepoCollection struct {
shouldErrorByStoragePrefixDistribution bool
@@ -579,4 +581,4 @@ func (s *PublishSourceUpdateSuite) TestErrorHandlingRobustness(c *C) {
c.Check(err, NotNil, Commentf("Scenario: %s", scenario.description))
c.Check(err.Error(), Matches, ".*"+scenario.expectedErr+".*", Commentf("Scenario: %s", scenario.description))
}
}
}
+39 -28
View File
@@ -313,8 +313,8 @@ func (s *PublishSwitchSuite) TestAptlyPublishSwitchEmptyComponentDefault(c *C) {
func (s *PublishSwitchSuite) TestAptlyPublishSwitchPrefixParsing(c *C) {
// Test different prefix formats
prefixTests := [][]string{
{"wheezy", ".", "wheezy-snapshot"}, // Default prefix
{"wheezy", "ppa", "wheezy-snapshot"}, // Simple prefix
{"wheezy", ".", "wheezy-snapshot"}, // Default prefix
{"wheezy", "ppa", "wheezy-snapshot"}, // Simple prefix
{"wheezy", "s3:bucket", "wheezy-snapshot"}, // Storage with prefix
}
@@ -340,21 +340,20 @@ func (m *MockPublishSwitchProgress) Printf(msg string, a ...interface{}) {
m.Messages = append(m.Messages, formatted)
}
func (m *MockPublishSwitchProgress) AddBar(count int) {}
func (m *MockPublishSwitchProgress) Flush() {}
func (m *MockPublishSwitchProgress) AddBar(count int) {}
func (m *MockPublishSwitchProgress) Flush() {}
func (m *MockPublishSwitchProgress) InitBar(total int64, colored bool, barType aptly.BarType) {}
func (m *MockPublishSwitchProgress) PrintfStdErr(msg string, a ...interface{}) {}
func (m *MockPublishSwitchProgress) SetBar(count int) {}
func (m *MockPublishSwitchProgress) Shutdown() {}
func (m *MockPublishSwitchProgress) ShutdownBar() {}
func (m *MockPublishSwitchProgress) Start() {}
func (m *MockPublishSwitchProgress) Write(data []byte) (int, error) { return len(data), nil }
func (m *MockPublishSwitchProgress) PrintfStdErr(msg string, a ...interface{}) {}
func (m *MockPublishSwitchProgress) SetBar(count int) {}
func (m *MockPublishSwitchProgress) Shutdown() {}
func (m *MockPublishSwitchProgress) ShutdownBar() {}
func (m *MockPublishSwitchProgress) Start() {}
func (m *MockPublishSwitchProgress) Write(data []byte) (int, error) { return len(data), nil }
func (m *MockPublishSwitchProgress) ColoredPrintf(msg string, a ...interface{}) {
formatted := fmt.Sprintf(msg, a...)
m.ColoredMessages = append(m.ColoredMessages, formatted)
}
type MockPublishSwitchContext struct {
flags *flag.FlagSet
progress *MockPublishSwitchProgress
@@ -364,22 +363,34 @@ type MockPublishSwitchContext struct {
signerError bool
}
func (m *MockPublishSwitchContext) Flags() *flag.FlagSet { return m.flags }
func (m *MockPublishSwitchContext) Progress() aptly.Progress { return m.progress }
func (m *MockPublishSwitchContext) NewCollectionFactory() *deb.CollectionFactory { return m.collectionFactory }
func (m *MockPublishSwitchContext) PackagePool() aptly.PackagePool { return m.packagePool }
func (m *MockPublishSwitchContext) SkelPath() string { return m.skelPath }
func (m *MockPublishSwitchContext) Flags() *flag.FlagSet { return m.flags }
func (m *MockPublishSwitchContext) Progress() aptly.Progress { return m.progress }
func (m *MockPublishSwitchContext) NewCollectionFactory() *deb.CollectionFactory {
return m.collectionFactory
}
func (m *MockPublishSwitchContext) PackagePool() aptly.PackagePool { return m.packagePool }
func (m *MockPublishSwitchContext) SkelPath() string { return m.skelPath }
type MockPublishSwitchPackagePool struct{}
func (m *MockPublishSwitchPackagePool) GeneratePackageRefs() []string { return []string{} }
func (m *MockPublishSwitchPackagePool) FilepathList(progress aptly.Progress) ([]string, error) { return []string{}, nil }
func (m *MockPublishSwitchPackagePool) Import(srcPath, basename string, checksums *utils.ChecksumInfo, move bool, storage aptly.ChecksumStorage) (string, error) { return "/pool/path", nil }
func (m *MockPublishSwitchPackagePool) Verify(poolPath, basename string, checksums *utils.ChecksumInfo, checksumStorage aptly.ChecksumStorage) (string, bool, error) { return poolPath, true, nil }
func (m *MockPublishSwitchPackagePool) Open(filename string) (aptly.ReadSeekerCloser, error) { return nil, nil }
func (m *MockPublishSwitchPackagePool) FilepathList(progress aptly.Progress) ([]string, error) {
return []string{}, nil
}
func (m *MockPublishSwitchPackagePool) Import(srcPath, basename string, checksums *utils.ChecksumInfo, move bool, storage aptly.ChecksumStorage) (string, error) {
return "/pool/path", nil
}
func (m *MockPublishSwitchPackagePool) Verify(poolPath, basename string, checksums *utils.ChecksumInfo, checksumStorage aptly.ChecksumStorage) (string, bool, error) {
return poolPath, true, nil
}
func (m *MockPublishSwitchPackagePool) Open(filename string) (aptly.ReadSeekerCloser, error) {
return nil, nil
}
func (m *MockPublishSwitchPackagePool) Remove(filename string) (int64, error) { return 0, nil }
func (m *MockPublishSwitchPackagePool) Size(prefix string) (int64, error) { return 0, nil }
func (m *MockPublishSwitchPackagePool) LegacyPath(filename string, checksums *utils.ChecksumInfo) (string, error) { return "/legacy/" + filename, nil }
func (m *MockPublishSwitchPackagePool) Size(prefix string) (int64, error) { return 0, nil }
func (m *MockPublishSwitchPackagePool) LegacyPath(filename string, checksums *utils.ChecksumInfo) (string, error) {
return "/legacy/" + filename, nil
}
type MockPublishedSwitchRepoCollection struct {
shouldErrorByStoragePrefixDistribution bool
@@ -434,8 +445,8 @@ func (m *MockPublishedSwitchRepoCollection) CleanupPrefixComponentFiles(publishe
}
type MockSnapshotSwitchCollection struct {
shouldErrorByName bool
shouldErrorLoadComplete bool
shouldErrorByName bool
shouldErrorLoadComplete bool
}
func (m *MockSnapshotSwitchCollection) ByName(name string) (*deb.Snapshot, error) {
@@ -459,14 +470,14 @@ func (m *MockSnapshotSwitchCollection) LoadComplete(snapshot *deb.Snapshot) erro
type MockPublishSwitchSigner struct{}
func (m *MockPublishSwitchSigner) SetKey(keyRef string) {}
func (m *MockPublishSwitchSigner) SetKeyRing(keyring, secretKeyring string) {}
func (m *MockPublishSwitchSigner) SetKey(keyRef string) {}
func (m *MockPublishSwitchSigner) SetKeyRing(keyring, secretKeyring string) {}
func (m *MockPublishSwitchSigner) SetPassphrase(passphrase, passphraseFile string) {}
func (m *MockPublishSwitchSigner) SetBatch(batch bool) {}
func (m *MockPublishSwitchSigner) SetBatch(batch bool) {}
// Mock utils.StrSliceHasItem function
func init() {
// Note: Removed package-level function assignment
}
// Note: Removed package-level function assignment to fix compilation errors
// Note: Removed package-level function assignment to fix compilation errors
+49 -49
View File
@@ -44,7 +44,7 @@ func (s *PublishSuite) setupMockContext(c *C) {
flags.Bool("batch", false, "batch mode")
flags.String("architectures", "", "architectures")
flags.Bool("multi-dist", false, "multi distribution")
err := InitContext(flags)
c.Assert(err, IsNil)
}
@@ -52,13 +52,13 @@ func (s *PublishSuite) setupMockContext(c *C) {
func (s *PublishSuite) TestMakeCmdPublishSnapshot(c *C) {
// Test makeCmdPublishSnapshot command creation
cmd := makeCmdPublishSnapshot()
c.Check(cmd, NotNil)
c.Check(cmd.Run, NotNil)
c.Check(cmd.UsageLine, Equals, "snapshot <name> [[<endpoint>:]<prefix>]")
c.Check(cmd.Short, Equals, "publish snapshot")
c.Check(cmd.Long, Not(Equals), "")
// Check that expected flags are present
c.Check(cmd.Flag.Lookup("distribution"), NotNil)
c.Check(cmd.Flag.Lookup("component"), NotNil)
@@ -71,13 +71,13 @@ func (s *PublishSuite) TestMakeCmdPublishSnapshot(c *C) {
func (s *PublishSuite) TestMakeCmdPublishRepo(c *C) {
// Test makeCmdPublishRepo command creation
cmd := makeCmdPublishRepo()
c.Check(cmd, NotNil)
c.Check(cmd.Run, NotNil)
c.Check(cmd.UsageLine, Equals, "repo <name> [[<endpoint>:]<prefix>]")
c.Check(cmd.Short, Equals, "publish local repository")
c.Check(cmd.Long, Not(Equals), "")
// Should use the same function as snapshot but different name
c.Check(cmd.Run, Equals, aptlyPublishSnapshotOrRepo)
}
@@ -85,7 +85,7 @@ func (s *PublishSuite) TestMakeCmdPublishRepo(c *C) {
func (s *PublishSuite) TestPublishSnapshotOrRepoNoArgs(c *C) {
// Test aptlyPublishSnapshotOrRepo with no arguments
s.setupMockContext(c)
cmd := makeCmdPublishSnapshot()
err := aptlyPublishSnapshotOrRepo(cmd, []string{})
c.Check(err, Equals, commander.ErrCommandError)
@@ -94,11 +94,11 @@ func (s *PublishSuite) TestPublishSnapshotOrRepoNoArgs(c *C) {
func (s *PublishSuite) TestPublishSnapshotOrRepoTooManyArgs(c *C) {
// Test aptlyPublishSnapshotOrRepo with too many arguments
s.setupMockContext(c)
cmd := makeCmdPublishSnapshot()
// Set component to "main" which means we expect 1 snapshot + optional prefix
context.Flags().Set("component", "main")
// Too many args: 3 args when we expect max 2 (1 snapshot + 1 prefix)
err := aptlyPublishSnapshotOrRepo(cmd, []string{"snap1", "snap2", "snap3"})
c.Check(err, Equals, commander.ErrCommandError)
@@ -107,15 +107,15 @@ func (s *PublishSuite) TestPublishSnapshotOrRepoTooManyArgs(c *C) {
func (s *PublishSuite) TestPublishSnapshotOrRepoMultiComponent(c *C) {
// Test aptlyPublishSnapshotOrRepo with multiple components
s.setupMockContext(c)
cmd := makeCmdPublishSnapshot()
// Set multiple components
context.Flags().Set("component", "main,contrib,non-free")
// Should expect 3 snapshots (one per component)
err := aptlyPublishSnapshotOrRepo(cmd, []string{"snap1"}) // Too few
c.Check(err, Equals, commander.ErrCommandError)
err = aptlyPublishSnapshotOrRepo(cmd, []string{"snap1", "snap2", "snap3", "snap4", "snap5"}) // Too many
c.Check(err, Equals, commander.ErrCommandError)
}
@@ -123,13 +123,13 @@ func (s *PublishSuite) TestPublishSnapshotOrRepoMultiComponent(c *C) {
func (s *PublishSuite) TestMakeCmdPublishList(c *C) {
// Test makeCmdPublishList command creation
cmd := makeCmdPublishList()
c.Check(cmd, NotNil)
c.Check(cmd.Run, NotNil)
c.Check(cmd.UsageLine, Equals, "list")
c.Check(cmd.Short, Equals, "list published repositories")
c.Check(cmd.Long, Not(Equals), "")
// Check that expected flags are present
c.Check(cmd.Flag.Lookup("raw"), NotNil)
}
@@ -137,7 +137,7 @@ func (s *PublishSuite) TestMakeCmdPublishList(c *C) {
func (s *PublishSuite) TestMakeCmdPublishShow(c *C) {
// Test makeCmdPublishShow command creation
cmd := makeCmdPublishShow()
c.Check(cmd, NotNil)
c.Check(cmd.Run, NotNil)
c.Check(cmd.UsageLine, Equals, "show <distribution> [[<endpoint>:]<prefix>]")
@@ -148,13 +148,13 @@ func (s *PublishSuite) TestMakeCmdPublishShow(c *C) {
func (s *PublishSuite) TestMakeCmdPublishDrop(c *C) {
// Test makeCmdPublishDrop command creation
cmd := makeCmdPublishDrop()
c.Check(cmd, NotNil)
c.Check(cmd.Run, NotNil)
c.Check(cmd.UsageLine, Equals, "drop <distribution> [[<endpoint>:]<prefix>]")
c.Check(cmd.Short, Equals, "remove published repository")
c.Check(cmd.Long, Not(Equals), "")
// Check that expected flags are present
c.Check(cmd.Flag.Lookup("force-drop"), NotNil)
c.Check(cmd.Flag.Lookup("skip-cleanup"), NotNil)
@@ -163,13 +163,13 @@ func (s *PublishSuite) TestMakeCmdPublishDrop(c *C) {
func (s *PublishSuite) TestMakeCmdPublishUpdate(c *C) {
// Test makeCmdPublishUpdate command creation
cmd := makeCmdPublishUpdate()
c.Check(cmd, NotNil)
c.Check(cmd.Run, NotNil)
c.Check(cmd.UsageLine, Equals, "update <distribution> [[<endpoint>:]<prefix>]")
c.Check(cmd.Short, Equals, "update published repository")
c.Check(cmd.Long, Not(Equals), "")
// Check that expected flags are present
c.Check(cmd.Flag.Lookup("force-overwrite"), NotNil)
c.Check(cmd.Flag.Lookup("skip-signing"), NotNil)
@@ -178,13 +178,13 @@ func (s *PublishSuite) TestMakeCmdPublishUpdate(c *C) {
func (s *PublishSuite) TestMakeCmdPublishSwitch(c *C) {
// Test makeCmdPublishSwitch command creation
cmd := makeCmdPublishSwitch()
c.Check(cmd, NotNil)
c.Check(cmd.Run, NotNil)
c.Check(cmd.UsageLine, Equals, "switch <distribution> [<component1>:]<name1> [<component2>:]<name2> ... [[<endpoint>:]<prefix>]")
c.Check(cmd.Short, Equals, "update published repository by switching to new snapshot")
c.Check(cmd.Long, Not(Equals), "")
// Check that expected flags are present
c.Check(cmd.Flag.Lookup("force-overwrite"), NotNil)
c.Check(cmd.Flag.Lookup("skip-signing"), NotNil)
@@ -194,7 +194,7 @@ func (s *PublishSuite) TestMakeCmdPublishSwitch(c *C) {
func (s *PublishSuite) TestPublishListNoArgs(c *C) {
// Test aptlyPublishList with no arguments (should work)
s.setupMockContext(c)
err := aptlyPublishList(makeCmdPublishList(), []string{})
// Will likely error due to no real collection factory, but tests structure
c.Check(err, NotNil)
@@ -203,7 +203,7 @@ func (s *PublishSuite) TestPublishListNoArgs(c *C) {
func (s *PublishSuite) TestPublishListWithArgs(c *C) {
// Test aptlyPublishList with arguments (should fail)
s.setupMockContext(c)
err := aptlyPublishList(makeCmdPublishList(), []string{"extra", "args"})
c.Check(err, Equals, commander.ErrCommandError)
}
@@ -211,7 +211,7 @@ func (s *PublishSuite) TestPublishListWithArgs(c *C) {
func (s *PublishSuite) TestPublishShowNoArgs(c *C) {
// Test aptlyPublishShow with no arguments
s.setupMockContext(c)
err := aptlyPublishShow(makeCmdPublishShow(), []string{})
c.Check(err, Equals, commander.ErrCommandError)
}
@@ -219,7 +219,7 @@ func (s *PublishSuite) TestPublishShowNoArgs(c *C) {
func (s *PublishSuite) TestPublishDropNoArgs(c *C) {
// Test aptlyPublishDrop with no arguments
s.setupMockContext(c)
err := aptlyPublishDrop(makeCmdPublishDrop(), []string{})
c.Check(err, Equals, commander.ErrCommandError)
}
@@ -227,7 +227,7 @@ func (s *PublishSuite) TestPublishDropNoArgs(c *C) {
func (s *PublishSuite) TestPublishUpdateNoArgs(c *C) {
// Test aptlyPublishUpdate with no arguments
s.setupMockContext(c)
err := aptlyPublishUpdate(makeCmdPublishUpdate(), []string{})
c.Check(err, Equals, commander.ErrCommandError)
}
@@ -235,10 +235,10 @@ func (s *PublishSuite) TestPublishUpdateNoArgs(c *C) {
func (s *PublishSuite) TestPublishSwitchInsufficientArgs(c *C) {
// Test aptlyPublishSwitch with insufficient arguments
s.setupMockContext(c)
err := aptlyPublishSwitch(makeCmdPublishSwitch(), []string{})
c.Check(err, Equals, commander.ErrCommandError)
err = aptlyPublishSwitch(makeCmdPublishSwitch(), []string{"distribution-only"})
c.Check(err, Equals, commander.ErrCommandError)
}
@@ -254,7 +254,7 @@ func (s *PublishSuite) TestPublishCommandFlags(c *C) {
makeCmdPublishUpdate(),
makeCmdPublishSwitch(),
}
for _, cmd := range commands {
c.Check(cmd, NotNil, Commentf("Command should not be nil: %s", cmd.Name()))
c.Check(cmd.Run, NotNil, Commentf("Command run function should not be nil: %s", cmd.Name()))
@@ -266,11 +266,11 @@ func (s *PublishSuite) TestPublishCommandFlags(c *C) {
func (s *PublishSuite) TestPublishPrefixParsing(c *C) {
// Test prefix parsing patterns used in publish commands
// Mock prefix parsing similar to deb.ParsePrefix
testCases := []struct {
input string
expectedStore string
input string
expectedStore string
expectedPrefix string
}{
{"", "", ""},
@@ -279,12 +279,12 @@ func (s *PublishSuite) TestPublishPrefixParsing(c *C) {
{"s3:us-east-1:bucket/prefix", "s3:us-east-1", "bucket/prefix"},
{"filesystem:/path/to/dir", "filesystem", "/path/to/dir"},
}
for _, tc := range testCases {
// Simple parsing logic for testing
parts := strings.SplitN(tc.input, ":", 2)
var storage, prefix string
if len(parts) == 1 {
storage = ""
prefix = parts[0]
@@ -299,7 +299,7 @@ func (s *PublishSuite) TestPublishPrefixParsing(c *C) {
prefix = parts[1]
}
}
c.Check(storage, Equals, tc.expectedStore, Commentf("Input: %s", tc.input))
c.Check(prefix, Equals, tc.expectedPrefix, Commentf("Input: %s", tc.input))
}
@@ -317,7 +317,7 @@ func (s *PublishSuite) TestComponentParsing(c *C) {
{"", []string{""}},
{"single", []string{"single"}},
}
for _, tc := range testCases {
components := strings.Split(tc.input, ",")
c.Check(components, DeepEquals, tc.expected, Commentf("Input: %s", tc.input))
@@ -327,7 +327,7 @@ func (s *PublishSuite) TestComponentParsing(c *C) {
func (s *PublishSuite) TestPublishErrorHandling(c *C) {
// Test error handling patterns in publish commands
s.setupMockContext(c)
// Test various error scenarios
commands := []struct {
name string
@@ -343,7 +343,7 @@ func (s *PublishSuite) TestPublishErrorHandling(c *C) {
{"publish update no args", makeCmdPublishUpdate(), aptlyPublishUpdate, []string{}, true},
{"publish switch no args", makeCmdPublishSwitch(), aptlyPublishSwitch, []string{}, true},
}
for _, tc := range commands {
err := tc.fn(tc.cmd, tc.args)
if tc.wantErr {
@@ -357,29 +357,29 @@ func (s *PublishSuite) TestPublishErrorHandling(c *C) {
func (s *PublishSuite) TestPublishArgumentValidation(c *C) {
// Test argument validation patterns
s.setupMockContext(c)
// Test component/argument count validation
testCases := []struct {
components string
args []string
valid bool
}{
{"main", []string{"snap1"}, true}, // 1 component, 1 snapshot
{"main", []string{"snap1", "prefix"}, true}, // 1 component, 1 snapshot + prefix
{"main", []string{}, false}, // 1 component, no snapshots
{"main", []string{"snap1", "snap2", "prefix"}, false}, // 1 component, too many args
{"main,contrib", []string{"snap1", "snap2"}, true}, // 2 components, 2 snapshots
{"main", []string{"snap1"}, true}, // 1 component, 1 snapshot
{"main", []string{"snap1", "prefix"}, true}, // 1 component, 1 snapshot + prefix
{"main", []string{}, false}, // 1 component, no snapshots
{"main", []string{"snap1", "snap2", "prefix"}, false}, // 1 component, too many args
{"main,contrib", []string{"snap1", "snap2"}, true}, // 2 components, 2 snapshots
{"main,contrib", []string{"snap1", "snap2", "prefix"}, true}, // 2 components, 2 snapshots + prefix
{"main,contrib", []string{"snap1"}, false}, // 2 components, not enough snapshots
{"main,contrib", []string{"snap1"}, false}, // 2 components, not enough snapshots
}
for _, tc := range testCases {
components := strings.Split(tc.components, ",")
args := tc.args
// Validation logic similar to aptlyPublishSnapshotOrRepo
valid := len(args) >= len(components) && len(args) <= len(components)+1
c.Check(valid, Equals, tc.valid, Commentf("Components: %s, Args: %v", tc.components, tc.args))
}
}
@@ -394,7 +394,7 @@ func (s *PublishSuite) TestPublishSourceCommands(c *C) {
makeCmdPublishSourceReplace(),
makeCmdPublishSourceUpdate(),
}
for _, cmd := range sourceCommands {
c.Check(cmd, NotNil)
c.Check(cmd.Run, NotNil)
@@ -402,4 +402,4 @@ func (s *PublishSuite) TestPublishSourceCommands(c *C) {
c.Check(cmd.Short, Not(Equals), "")
c.Check(strings.Contains(cmd.Short, "source"), Equals, true)
}
}
}
+39 -27
View File
@@ -251,10 +251,10 @@ func (s *PublishUpdateSuite) TestAptlyPublishUpdateWithUpdateResult(c *C) {
func (s *PublishUpdateSuite) TestAptlyPublishUpdatePrefixParsing(c *C) {
// Test different prefix formats
prefixTests := [][]string{
{"wheezy"}, // Default prefix
{"wheezy", "."}, // Explicit default prefix
{"wheezy", "ppa"}, // Simple prefix
{"wheezy", "s3:bucket"}, // Storage with prefix
{"wheezy"}, // Default prefix
{"wheezy", "."}, // Explicit default prefix
{"wheezy", "ppa"}, // Simple prefix
{"wheezy", "s3:bucket"}, // Storage with prefix
}
for _, args := range prefixTests {
@@ -312,15 +312,15 @@ func (m *MockPublishUpdateProgress) ColoredPrintf(msg string, a ...interface{})
m.ColoredMessages = append(m.ColoredMessages, formatted)
}
func (m *MockPublishUpdateProgress) AddBar(count int) {}
func (m *MockPublishUpdateProgress) Flush() {}
func (m *MockPublishUpdateProgress) AddBar(count int) {}
func (m *MockPublishUpdateProgress) Flush() {}
func (m *MockPublishUpdateProgress) InitBar(total int64, colored bool, barType aptly.BarType) {}
func (m *MockPublishUpdateProgress) PrintfStdErr(msg string, a ...interface{}) {}
func (m *MockPublishUpdateProgress) SetBar(count int) {}
func (m *MockPublishUpdateProgress) Shutdown() {}
func (m *MockPublishUpdateProgress) ShutdownBar() {}
func (m *MockPublishUpdateProgress) Start() {}
func (m *MockPublishUpdateProgress) Write(data []byte) (int, error) { return len(data), nil }
func (m *MockPublishUpdateProgress) PrintfStdErr(msg string, a ...interface{}) {}
func (m *MockPublishUpdateProgress) SetBar(count int) {}
func (m *MockPublishUpdateProgress) Shutdown() {}
func (m *MockPublishUpdateProgress) ShutdownBar() {}
func (m *MockPublishUpdateProgress) Start() {}
func (m *MockPublishUpdateProgress) Write(data []byte) (int, error) { return len(data), nil }
type MockPublishUpdateContext struct {
flags *flag.FlagSet
@@ -331,22 +331,34 @@ type MockPublishUpdateContext struct {
signerError bool
}
func (m *MockPublishUpdateContext) Flags() *flag.FlagSet { return m.flags }
func (m *MockPublishUpdateContext) Progress() aptly.Progress { return m.progress }
func (m *MockPublishUpdateContext) NewCollectionFactory() *deb.CollectionFactory { return m.collectionFactory }
func (m *MockPublishUpdateContext) PackagePool() aptly.PackagePool { return m.packagePool }
func (m *MockPublishUpdateContext) SkelPath() string { return m.skelPath }
func (m *MockPublishUpdateContext) Flags() *flag.FlagSet { return m.flags }
func (m *MockPublishUpdateContext) Progress() aptly.Progress { return m.progress }
func (m *MockPublishUpdateContext) NewCollectionFactory() *deb.CollectionFactory {
return m.collectionFactory
}
func (m *MockPublishUpdateContext) PackagePool() aptly.PackagePool { return m.packagePool }
func (m *MockPublishUpdateContext) SkelPath() string { return m.skelPath }
type MockUpdatePackagePool struct{}
func (m *MockUpdatePackagePool) GeneratePackageRefs() []string { return []string{} }
func (m *MockUpdatePackagePool) FilepathList(progress aptly.Progress) ([]string, error) { return []string{}, nil }
func (m *MockUpdatePackagePool) Import(srcPath, basename string, checksums *utils.ChecksumInfo, move bool, storage aptly.ChecksumStorage) (string, error) { return "/pool/path", nil }
func (m *MockUpdatePackagePool) Verify(poolPath, basename string, checksums *utils.ChecksumInfo, checksumStorage aptly.ChecksumStorage) (string, bool, error) { return poolPath, true, nil }
func (m *MockUpdatePackagePool) Open(filename string) (aptly.ReadSeekerCloser, error) { return nil, nil }
func (m *MockUpdatePackagePool) FilepathList(progress aptly.Progress) ([]string, error) {
return []string{}, nil
}
func (m *MockUpdatePackagePool) Import(srcPath, basename string, checksums *utils.ChecksumInfo, move bool, storage aptly.ChecksumStorage) (string, error) {
return "/pool/path", nil
}
func (m *MockUpdatePackagePool) Verify(poolPath, basename string, checksums *utils.ChecksumInfo, checksumStorage aptly.ChecksumStorage) (string, bool, error) {
return poolPath, true, nil
}
func (m *MockUpdatePackagePool) Open(filename string) (aptly.ReadSeekerCloser, error) {
return nil, nil
}
func (m *MockUpdatePackagePool) Remove(filename string) (int64, error) { return 0, nil }
func (m *MockUpdatePackagePool) Size(prefix string) (int64, error) { return 0, nil }
func (m *MockUpdatePackagePool) LegacyPath(filename string, checksums *utils.ChecksumInfo) (string, error) { return "/legacy/" + filename, nil }
func (m *MockUpdatePackagePool) Size(prefix string) (int64, error) { return 0, nil }
func (m *MockUpdatePackagePool) LegacyPath(filename string, checksums *utils.ChecksumInfo) (string, error) {
return "/legacy/" + filename, nil
}
type MockPublishedUpdateRepoCollection struct {
shouldErrorByStoragePrefixDistribution bool
@@ -404,12 +416,12 @@ func (m *MockPublishedUpdateRepoCollection) CleanupPrefixComponentFiles(publishe
type MockUpdateSigner struct{}
func (m *MockUpdateSigner) SetKey(keyRef string) {}
func (m *MockUpdateSigner) SetKeyRing(keyring, secretKeyring string) {}
func (m *MockUpdateSigner) SetKey(keyRef string) {}
func (m *MockUpdateSigner) SetKeyRing(keyring, secretKeyring string) {}
func (m *MockUpdateSigner) SetPassphrase(passphrase, passphraseFile string) {}
func (m *MockUpdateSigner) SetBatch(batch bool) {}
func (m *MockUpdateSigner) SetBatch(batch bool) {}
// Mock deb.ParsePrefix function for update tests
func init() {
// Note: Removed package-level function assignment
}
}
+64 -64
View File
@@ -7,8 +7,8 @@ import (
"testing"
"github.com/aptly-dev/aptly/aptly"
"github.com/aptly-dev/aptly/deb"
ctx "github.com/aptly-dev/aptly/context"
"github.com/aptly-dev/aptly/deb"
"github.com/smira/commander"
"github.com/smira/flag"
. "gopkg.in/check.v1"
@@ -40,7 +40,7 @@ func (s *RepoAddSuite) setupMockContext(c *C) {
flags := flag.NewFlagSet("test", flag.ContinueOnError)
flags.Bool("remove-files", false, "remove files")
flags.Bool("force-replace", false, "force replace")
err := InitContext(flags)
c.Assert(err, IsNil)
}
@@ -48,21 +48,21 @@ func (s *RepoAddSuite) setupMockContext(c *C) {
func (s *RepoAddSuite) TestMakeCmdRepoAdd(c *C) {
// Test that makeCmdRepoAdd creates a proper command
cmd := makeCmdRepoAdd()
c.Check(cmd, NotNil)
c.Check(cmd.Run, NotNil)
c.Check(cmd.UsageLine, Equals, "add <name> (<package file.deb>|<directory>)...")
c.Check(cmd.Short, Equals, "add packages to local repository")
c.Check(cmd.Long, Not(Equals), "")
// Check that all expected flags are present
c.Check(cmd.Flag.Lookup("remove-files"), NotNil)
c.Check(cmd.Flag.Lookup("force-replace"), NotNil)
// Check flag default values
removeFilesFlag := cmd.Flag.Lookup("remove-files")
c.Check(removeFilesFlag.DefValue, Equals, "false")
forceReplaceFlag := cmd.Flag.Lookup("force-replace")
c.Check(forceReplaceFlag.DefValue, Equals, "false")
}
@@ -70,7 +70,7 @@ func (s *RepoAddSuite) TestMakeCmdRepoAdd(c *C) {
func (s *RepoAddSuite) TestAptlyRepoAddNoArgs(c *C) {
// Test aptlyRepoAdd with no arguments
s.setupMockContext(c)
err := aptlyRepoAdd(s.cmd, []string{})
c.Check(err, Equals, commander.ErrCommandError)
}
@@ -78,7 +78,7 @@ func (s *RepoAddSuite) TestAptlyRepoAddNoArgs(c *C) {
func (s *RepoAddSuite) TestAptlyRepoAddOneArg(c *C) {
// Test aptlyRepoAdd with only repository name (no files)
s.setupMockContext(c)
err := aptlyRepoAdd(s.cmd, []string{"test-repo"})
c.Check(err, Equals, commander.ErrCommandError)
}
@@ -86,7 +86,7 @@ func (s *RepoAddSuite) TestAptlyRepoAddOneArg(c *C) {
func (s *RepoAddSuite) TestAptlyRepoAddNonexistentRepo(c *C) {
// Test aptlyRepoAdd with nonexistent repository
s.setupMockContext(c)
err := aptlyRepoAdd(s.cmd, []string{"nonexistent-repo", "some-file.deb"})
c.Check(err, NotNil)
c.Check(err.Error(), Matches, "unable to add:.*")
@@ -95,7 +95,7 @@ func (s *RepoAddSuite) TestAptlyRepoAddNonexistentRepo(c *C) {
func (s *RepoAddSuite) TestCommandUsage(c *C) {
// Test command usage information
cmd := makeCmdRepoAdd()
c.Check(cmd.UsageLine, Equals, "add <name> (<package file.deb>|<directory>)...")
c.Check(cmd.Short, Equals, "add packages to local repository")
c.Check(cmd.Long, Matches, "(?s).*Command adds packages to local repository.*")
@@ -120,7 +120,7 @@ func (s *RepoAddSuite) TestRepoAddErrorHandling(c *C) {
expected: commander.ErrCommandError.Error(),
},
}
for _, tc := range testCases {
s.setupMockContext(c)
err := aptlyRepoAdd(s.cmd, tc.args)
@@ -135,13 +135,13 @@ func (s *RepoAddSuite) TestRepoAddErrorHandling(c *C) {
func (s *RepoAddSuite) TestFileHandlingPatterns(c *C) {
// Test file handling patterns used in aptlyRepoAdd
// Create test files
debFile := filepath.Join(s.tempDir, "test-package.deb")
udebFile := filepath.Join(s.tempDir, "test-package.udeb")
dscFile := filepath.Join(s.tempDir, "test-package.dsc")
txtFile := filepath.Join(s.tempDir, "readme.txt")
// Create the files
for _, filename := range []string{debFile, udebFile, dscFile, txtFile} {
file, err := os.Create(filename)
@@ -149,13 +149,13 @@ func (s *RepoAddSuite) TestFileHandlingPatterns(c *C) {
file.WriteString("test content")
file.Close()
}
// Test file collection patterns (similar to deb.CollectPackageFiles)
files := []string{debFile, udebFile, dscFile, txtFile}
packageFiles := []string{}
otherFiles := []string{}
for _, file := range files {
if filepath.Ext(file) == ".deb" || filepath.Ext(file) == ".udeb" || filepath.Ext(file) == ".dsc" {
packageFiles = append(packageFiles, file)
@@ -163,7 +163,7 @@ func (s *RepoAddSuite) TestFileHandlingPatterns(c *C) {
otherFiles = append(otherFiles, file)
}
}
c.Check(len(packageFiles), Equals, 3)
c.Check(len(otherFiles), Equals, 1)
c.Check(packageFiles[0], Matches, ".*\\.deb$")
@@ -174,30 +174,30 @@ func (s *RepoAddSuite) TestFileHandlingPatterns(c *C) {
func (s *RepoAddSuite) TestFileRemovalPattern(c *C) {
// Test the file removal pattern used when --remove-files is set
// Create test files
testFiles := []string{
filepath.Join(s.tempDir, "file1.deb"),
filepath.Join(s.tempDir, "file2.deb"),
filepath.Join(s.tempDir, "file3.deb"),
}
for _, filename := range testFiles {
file, err := os.Create(filename)
c.Assert(err, IsNil)
file.WriteString("test content")
file.Close()
// Verify file exists
_, err = os.Stat(filename)
c.Check(err, IsNil)
}
// Test removal pattern
for _, filename := range testFiles {
err := os.Remove(filename)
c.Check(err, IsNil)
// Verify file is gone
_, err = os.Stat(filename)
c.Check(os.IsNotExist(err), Equals, true)
@@ -206,7 +206,7 @@ func (s *RepoAddSuite) TestFileRemovalPattern(c *C) {
func (s *RepoAddSuite) TestFileDeduplication(c *C) {
// Test file deduplication pattern used in the function
// Create duplicate file list
files := []string{
"/path/to/file1.deb",
@@ -215,28 +215,28 @@ func (s *RepoAddSuite) TestFileDeduplication(c *C) {
"/path/to/file3.deb",
"/path/to/file2.deb", // duplicate
}
// Simple deduplication (similar to utils.StrSliceDeduplicate)
seen := make(map[string]bool)
deduplicated := []string{}
for _, file := range files {
if !seen[file] {
seen[file] = true
deduplicated = append(deduplicated, file)
}
}
c.Check(len(deduplicated), Equals, 3)
c.Check(len(files), Equals, 5)
// Verify all unique files are present
expectedFiles := []string{
"/path/to/file1.deb",
"/path/to/file2.deb",
"/path/to/file2.deb",
"/path/to/file3.deb",
}
for i, expected := range expectedFiles {
c.Check(deduplicated[i], Equals, expected)
}
@@ -244,23 +244,23 @@ func (s *RepoAddSuite) TestFileDeduplication(c *C) {
func (s *RepoAddSuite) TestPackageListHandling(c *C) {
// Test package list creation and manipulation patterns
// Mock package list structure
type mockPackageList struct {
packages []string
refs []string
}
list := &mockPackageList{
packages: []string{"package1", "package2"},
refs: []string{"ref1", "ref2"},
}
// Test adding packages to list
newPackages := []string{"package3", "package4"}
list.packages = append(list.packages, newPackages...)
list.refs = append(list.refs, "ref3", "ref4")
c.Check(len(list.packages), Equals, 4)
c.Check(len(list.refs), Equals, 4)
c.Check(list.packages[2], Equals, "package3")
@@ -269,14 +269,14 @@ func (s *RepoAddSuite) TestPackageListHandling(c *C) {
func (s *RepoAddSuite) TestErrorReporting(c *C) {
// Test error reporting patterns used in aptlyRepoAdd
// Test failed files collection
failedFiles := []string{}
processedFiles := []string{}
// Simulate processing files with some failures
files := []string{"file1.deb", "file2.deb", "file3.deb", "file4.deb"}
for i, file := range files {
if i%2 == 0 {
// Simulate success
@@ -286,14 +286,14 @@ func (s *RepoAddSuite) TestErrorReporting(c *C) {
failedFiles = append(failedFiles, file)
}
}
c.Check(len(processedFiles), Equals, 2)
c.Check(len(failedFiles), Equals, 2)
c.Check(processedFiles[0], Equals, "file1.deb")
c.Check(processedFiles[1], Equals, "file3.deb")
c.Check(failedFiles[0], Equals, "file2.deb")
c.Check(failedFiles[1], Equals, "file4.deb")
// Test error message generation
if len(failedFiles) > 0 {
err := errors.New("some files failed to be added")
@@ -303,27 +303,27 @@ func (s *RepoAddSuite) TestErrorReporting(c *C) {
func (s *RepoAddSuite) TestFlagProcessing(c *C) {
// Test flag processing patterns
cmd := makeCmdRepoAdd()
// Test setting flags
err := cmd.Flag.Set("remove-files", "true")
c.Check(err, IsNil)
err = cmd.Flag.Set("force-replace", "true")
c.Check(err, IsNil)
// Test reading flag values
removeFilesFlag := cmd.Flag.Lookup("remove-files")
c.Check(removeFilesFlag.Value.String(), Equals, "true")
forceReplaceFlag := cmd.Flag.Lookup("force-replace")
c.Check(forceReplaceFlag.Value.String(), Equals, "true")
}
func (s *RepoAddSuite) TestPackageImportFlow(c *C) {
// Test the package import flow structure
// Mock the import flow
type importResult struct {
processedFiles []string
@@ -331,16 +331,16 @@ func (s *RepoAddSuite) TestPackageImportFlow(c *C) {
otherFiles []string
err error
}
// Simulate package collection
inputFiles := []string{"package1.deb", "package2.deb", "readme.txt"}
result := &importResult{
processedFiles: []string{},
failedFiles: []string{},
otherFiles: []string{},
}
// Simulate file classification
for _, file := range inputFiles {
if filepath.Ext(file) == ".deb" {
@@ -349,10 +349,10 @@ func (s *RepoAddSuite) TestPackageImportFlow(c *C) {
result.otherFiles = append(result.otherFiles, file)
}
}
// Merge processed and other files (like in the real function)
allProcessed := append(result.processedFiles, result.otherFiles...)
c.Check(len(result.processedFiles), Equals, 2)
c.Check(len(result.otherFiles), Equals, 1)
c.Check(len(allProcessed), Equals, 3)
@@ -363,27 +363,27 @@ func (s *RepoAddSuite) TestPackageImportFlow(c *C) {
func (s *RepoAddSuite) TestRepositoryUpdate(c *C) {
// Test repository update patterns
// Mock repository
type mockRepo struct {
name string
refList []string
updated bool
}
repo := &mockRepo{
name: "test-repo",
refList: []string{"ref1", "ref2"},
updated: false,
}
// Simulate updating ref list
newRefs := []string{"ref3", "ref4"}
repo.refList = append(repo.refList, newRefs...)
// Simulate repository update
repo.updated = true
c.Check(len(repo.refList), Equals, 4)
c.Check(repo.updated, Equals, true)
c.Check(repo.refList[2], Equals, "ref3")
@@ -392,40 +392,40 @@ func (s *RepoAddSuite) TestRepositoryUpdate(c *C) {
func (s *RepoAddSuite) TestProgressReporting(c *C) {
// Test progress reporting patterns
type mockProgress struct {
messages []string
}
progress := &mockProgress{}
// Test progress messages used in the function
progress.messages = append(progress.messages, "Loading packages...")
c.Check(len(progress.messages), Equals, 1)
c.Check(progress.messages[0], Equals, "Loading packages...")
}
func (s *RepoAddSuite) TestVerifierUsage(c *C) {
// Test verifier usage pattern
// Mock verifier interface
type mockVerifier struct {
verified bool
}
verifier := &mockVerifier{verified: false}
// Simulate verification process
verifier.verified = true
c.Check(verifier.verified, Equals, true)
}
func (s *RepoAddSuite) TestCollectionFactoryUsage(c *C) {
// Test collection factory usage patterns - simplified
// Note: Complex mocking removed for compilation simplification
// Basic test to verify function works
c.Check(true, Equals, true)
}
}
+7 -7
View File
@@ -39,7 +39,7 @@ func (s *RepoCreateSuite) TestMakeCmdRepoCreate(c *C) {
func (s *RepoCreateSuite) TestRepoCreateBasic(c *C) {
// Test basic repository creation - simplified
args := []string{"test-repo"}
err := aptlyRepoCreate(s.cmd, args)
// Note: Actual behavior depends on real implementation
_ = err // May or may not error depending on implementation
@@ -49,7 +49,7 @@ func (s *RepoCreateSuite) TestRepoCreateWithComment(c *C) {
// Test repository creation with comment - simplified
s.cmd.Flag.Set("comment", "Test repository comment")
args := []string{"test-repo-with-comment"}
err := aptlyRepoCreate(s.cmd, args)
// Note: Actual behavior depends on real implementation
_ = err // May or may not error depending on implementation
@@ -59,7 +59,7 @@ func (s *RepoCreateSuite) TestRepoCreateWithDistribution(c *C) {
// Test repository creation with distribution - simplified
s.cmd.Flag.Set("distribution", "trusty")
args := []string{"test-repo-with-dist"}
err := aptlyRepoCreate(s.cmd, args)
// Note: Actual behavior depends on real implementation
_ = err // May or may not error depending on implementation
@@ -69,7 +69,7 @@ func (s *RepoCreateSuite) TestRepoCreateWithComponent(c *C) {
// Test repository creation with component - simplified
s.cmd.Flag.Set("component", "main")
args := []string{"test-repo-with-comp"}
err := aptlyRepoCreate(s.cmd, args)
// Note: Actual behavior depends on real implementation
_ = err // May or may not error depending on implementation
@@ -91,7 +91,7 @@ func (s *RepoCreateSuite) TestRepoCreateWithAllFlags(c *C) {
s.cmd.Flag.Set("distribution", "focal")
s.cmd.Flag.Set("component", "main")
args := []string{"test-repo-complete"}
err := aptlyRepoCreate(s.cmd, args)
// Note: Actual behavior depends on real implementation
_ = err // May or may not error depending on implementation
@@ -111,11 +111,11 @@ func (s *RepoCreateSuite) TestRepoCreateSpecialCharacters(c *C) {
"test_repo_with_underscores",
"test.repo.with.dots",
}
for _, name := range specialNames {
args := []string{name}
err := aptlyRepoCreate(s.cmd, args)
// Note: Actual behavior depends on validation rules
_ = err
}
}
}
+56 -36
View File
@@ -160,53 +160,69 @@ func (m *MockRepoIncludeProgress) ColoredPrintf(msg string, a ...interface{}) {
// Mock implementation
}
func (m *MockRepoIncludeProgress) AddBar(count int) {}
func (m *MockRepoIncludeProgress) Flush() {}
func (m *MockRepoIncludeProgress) AddBar(count int) {}
func (m *MockRepoIncludeProgress) Flush() {}
func (m *MockRepoIncludeProgress) InitBar(total int64, colored bool, barType aptly.BarType) {}
func (m *MockRepoIncludeProgress) PrintfStdErr(msg string, a ...interface{}) {}
func (m *MockRepoIncludeProgress) SetBar(count int) {}
func (m *MockRepoIncludeProgress) Shutdown() {}
func (m *MockRepoIncludeProgress) ShutdownBar() {}
func (m *MockRepoIncludeProgress) Start() {}
func (m *MockRepoIncludeProgress) Write(data []byte) (int, error) { return len(data), nil }
func (m *MockRepoIncludeProgress) PrintfStdErr(msg string, a ...interface{}) {}
func (m *MockRepoIncludeProgress) SetBar(count int) {}
func (m *MockRepoIncludeProgress) Shutdown() {}
func (m *MockRepoIncludeProgress) ShutdownBar() {}
func (m *MockRepoIncludeProgress) Start() {}
func (m *MockRepoIncludeProgress) Write(data []byte) (int, error) { return len(data), nil }
type MockRepoIncludeContext struct {
flags *flag.FlagSet
progress *MockRepoIncludeProgress
collectionFactory *deb.CollectionFactory
config *utils.ConfigStructure
packagePool aptly.PackagePool
verifier pgp.Verifier
verifierError bool
nilVerifier bool
uploadersError bool
uploadersQueryError bool
hasFailedFiles bool
flags *flag.FlagSet
progress *MockRepoIncludeProgress
collectionFactory *deb.CollectionFactory
config *utils.ConfigStructure
packagePool aptly.PackagePool
verifier pgp.Verifier
verifierError bool
nilVerifier bool
uploadersError bool
uploadersQueryError bool
hasFailedFiles bool
}
func (m *MockRepoIncludeContext) Flags() *flag.FlagSet { return m.flags }
func (m *MockRepoIncludeContext) Progress() aptly.Progress { return m.progress }
func (m *MockRepoIncludeContext) NewCollectionFactory() *deb.CollectionFactory { return m.collectionFactory }
func (m *MockRepoIncludeContext) Config() *utils.ConfigStructure { return m.config }
func (m *MockRepoIncludeContext) PackagePool() aptly.PackagePool { return m.packagePool }
func (m *MockRepoIncludeContext) Flags() *flag.FlagSet { return m.flags }
func (m *MockRepoIncludeContext) Progress() aptly.Progress { return m.progress }
func (m *MockRepoIncludeContext) NewCollectionFactory() *deb.CollectionFactory {
return m.collectionFactory
}
func (m *MockRepoIncludeContext) Config() *utils.ConfigStructure { return m.config }
func (m *MockRepoIncludeContext) PackagePool() aptly.PackagePool { return m.packagePool }
type MockRepoIncludePackagePool struct{}
func (m *MockRepoIncludePackagePool) FilepathList(progress aptly.Progress) ([]string, error) { return []string{}, nil }
func (m *MockRepoIncludePackagePool) FilepathList(progress aptly.Progress) ([]string, error) {
return []string{}, nil
}
func (m *MockRepoIncludePackagePool) GeneratePackageRefs() []string { return []string{} }
func (m *MockRepoIncludePackagePool) Import(srcPath, basename string, checksums *utils.ChecksumInfo, move bool, storage aptly.ChecksumStorage) (string, error) { return "/pool/path", nil }
func (m *MockRepoIncludePackagePool) Verify(poolPath, basename string, checksums *utils.ChecksumInfo, checksumStorage aptly.ChecksumStorage) (string, bool, error) { return poolPath, true, nil }
func (m *MockRepoIncludePackagePool) Open(filename string) (aptly.ReadSeekerCloser, error) { return nil, nil }
func (m *MockRepoIncludePackagePool) Import(srcPath, basename string, checksums *utils.ChecksumInfo, move bool, storage aptly.ChecksumStorage) (string, error) {
return "/pool/path", nil
}
func (m *MockRepoIncludePackagePool) Verify(poolPath, basename string, checksums *utils.ChecksumInfo, checksumStorage aptly.ChecksumStorage) (string, bool, error) {
return poolPath, true, nil
}
func (m *MockRepoIncludePackagePool) Open(filename string) (aptly.ReadSeekerCloser, error) {
return nil, nil
}
func (m *MockRepoIncludePackagePool) Remove(filename string) (int64, error) { return 0, nil }
func (m *MockRepoIncludePackagePool) Size(prefix string) (int64, error) { return 0, nil }
func (m *MockRepoIncludePackagePool) LegacyPath(filename string, checksums *utils.ChecksumInfo) (string, error) { return "/legacy/" + filename, nil }
func (m *MockRepoIncludePackagePool) Size(prefix string) (int64, error) { return 0, nil }
func (m *MockRepoIncludePackagePool) LegacyPath(filename string, checksums *utils.ChecksumInfo) (string, error) {
return "/legacy/" + filename, nil
}
type MockRepoIncludeVerifier struct{}
func (m *MockRepoIncludeVerifier) AddKeyring(keyring string) {}
func (m *MockRepoIncludeVerifier) AddKeyring(keyring string) {}
func (m *MockRepoIncludeVerifier) InitKeyring(verbose bool) error { return nil }
func (m *MockRepoIncludeVerifier) VerifyDetachedSignature(signature, message io.Reader, showKeyInfo bool) error { return nil }
func (m *MockRepoIncludeVerifier) ExtractClearsign(data []byte) (content []byte, err error) { return data, nil }
func (m *MockRepoIncludeVerifier) VerifyDetachedSignature(signature, message io.Reader, showKeyInfo bool) error {
return nil
}
func (m *MockRepoIncludeVerifier) ExtractClearsign(data []byte) (content []byte, err error) {
return data, nil
}
func (m *MockRepoIncludeVerifier) ExtractClearsigned(clearsigned io.Reader) (text *os.File, err error) {
// Create a temporary file for testing
tmpFile, err := os.CreateTemp("", "mock-clearsigned")
@@ -223,7 +239,11 @@ func (m *MockRepoIncludeVerifier) ExtractClearsigned(clearsigned io.Reader) (tex
tmpFile.Seek(0, 0)
return tmpFile, nil
}
func (m *MockRepoIncludeVerifier) IsClearSigned(clearsigned io.Reader) (bool, error) { return true, nil }
func (m *MockRepoIncludeVerifier) VerifyClearsigned(clearsigned io.Reader, showKeyInfo bool) (*pgp.KeyInfo, error) { return &pgp.KeyInfo{}, nil }
func (m *MockRepoIncludeVerifier) IsClearSigned(clearsigned io.Reader) (bool, error) {
return true, nil
}
func (m *MockRepoIncludeVerifier) VerifyClearsigned(clearsigned io.Reader, showKeyInfo bool) (*pgp.KeyInfo, error) {
return &pgp.KeyInfo{}, nil
}
// Note: Removed package-level function assignments to fix compilation errors
// Note: Removed package-level function assignments to fix compilation errors
+1 -1
View File
@@ -41,4 +41,4 @@ func (s *RepoListSimpleSuite) TestAptlyRepoListBasic(c *C) {
// This may fail due to missing context, but should not panic
_ = aptlyRepoList(s.cmd, args)
}
}
+1 -1
View File
@@ -99,4 +99,4 @@ func (s *RepoMoveSimpleSuite) TestAptlyRepoMoveMultipleQueries(c *C) {
// Test with multiple package queries
args := []string{"src-repo", "dst-repo", "package1", "package2", "package3"}
_ = aptlyRepoMoveCopyImport(s.cmd, args)
}
}
+1 -1
View File
@@ -79,4 +79,4 @@ func (s *RepoRemoveSimpleSuite) TestAptlyRepoRemoveMultipleQueries(c *C) {
// Test with multiple package queries
args := []string{"repo-name", "package1", "package2", "package3"}
_ = aptlyRepoRemove(s.cmd, args)
}
}
+1 -1
View File
@@ -83,4 +83,4 @@ func (s *RepoShowSimpleSuite) TestAptlyRepoShowWithAllFlags(c *C) {
args := []string{"repo-name"}
_ = aptlyRepoShow(s.cmd, args)
}
}
+1 -1
View File
@@ -70,4 +70,4 @@ func (s *ServeSimpleSuite) TestAptlyServeWithNoLock(c *C) {
args := []string{}
_ = aptlyServe(s.cmd, args)
}
}
+51 -51
View File
@@ -11,8 +11,8 @@ import (
)
type SnapshotCreateSuite struct {
cmd *commander.Command
origStdout *os.File
cmd *commander.Command
origStdout *os.File
}
var _ = Suite(&SnapshotCreateSuite{})
@@ -29,13 +29,13 @@ func (s *SnapshotCreateSuite) TearDownTest(c *C) {
func (s *SnapshotCreateSuite) TestSnapshotCreateEmpty(c *C) {
// Test creating empty snapshot
args := []string{"empty-snapshot", "empty"}
var buf bytes.Buffer
os.Stdout = &buf
err := aptlySnapshotCreate(s.cmd, args)
c.Check(err, IsNil)
output := buf.String()
c.Check(strings.Contains(output, "Snapshot empty-snapshot successfully created"), Equals, true)
c.Check(strings.Contains(output, "aptly publish snapshot empty-snapshot"), Equals, true)
@@ -44,7 +44,7 @@ func (s *SnapshotCreateSuite) TestSnapshotCreateEmpty(c *C) {
func (s *SnapshotCreateSuite) TestSnapshotCreateFromMirror(c *C) {
// Test creating snapshot from mirror (will fail due to no context/mirror)
args := []string{"mirror-snapshot", "from", "mirror", "test-mirror"}
err := aptlySnapshotCreate(s.cmd, args)
c.Check(err, NotNil)
c.Check(err.Error(), Matches, ".*unable to create snapshot.*")
@@ -53,7 +53,7 @@ func (s *SnapshotCreateSuite) TestSnapshotCreateFromMirror(c *C) {
func (s *SnapshotCreateSuite) TestSnapshotCreateFromRepo(c *C) {
// Test creating snapshot from local repo (will fail due to no context/repo)
args := []string{"repo-snapshot", "from", "repo", "test-repo"}
err := aptlySnapshotCreate(s.cmd, args)
c.Check(err, NotNil)
c.Check(err.Error(), Matches, ".*unable to create snapshot.*")
@@ -63,27 +63,27 @@ func (s *SnapshotCreateSuite) TestSnapshotCreateInvalidArgs(c *C) {
// Test with no arguments
err := aptlySnapshotCreate(s.cmd, []string{})
c.Check(err, Equals, commander.ErrCommandError)
// Test with only name
err = aptlySnapshotCreate(s.cmd, []string{"test"})
c.Check(err, Equals, commander.ErrCommandError)
// Test with wrong syntax
err = aptlySnapshotCreate(s.cmd, []string{"test", "invalid"})
c.Check(err, Equals, commander.ErrCommandError)
// Test with incomplete "from mirror"
err = aptlySnapshotCreate(s.cmd, []string{"test", "from", "mirror"})
c.Check(err, Equals, commander.ErrCommandError)
// Test with incomplete "from repo"
err = aptlySnapshotCreate(s.cmd, []string{"test", "from", "repo"})
c.Check(err, Equals, commander.ErrCommandError)
// Test with wrong "from" syntax
err = aptlySnapshotCreate(s.cmd, []string{"test", "from", "invalid", "source"})
c.Check(err, Equals, commander.ErrCommandError)
// Test with too many arguments
err = aptlySnapshotCreate(s.cmd, []string{"test", "from", "mirror", "source", "extra"})
c.Check(err, Equals, commander.ErrCommandError)
@@ -92,7 +92,7 @@ func (s *SnapshotCreateSuite) TestSnapshotCreateInvalidArgs(c *C) {
func (s *SnapshotCreateSuite) TestSnapshotCreateValidSyntaxFromMirror(c *C) {
// Test that valid "from mirror" syntax passes argument validation
args := []string{"valid-mirror-snapshot", "from", "mirror", "test-mirror"}
// This will fail at mirror loading but pass argument validation
err := aptlySnapshotCreate(s.cmd, args)
c.Check(err, NotNil)
@@ -104,7 +104,7 @@ func (s *SnapshotCreateSuite) TestSnapshotCreateValidSyntaxFromMirror(c *C) {
func (s *SnapshotCreateSuite) TestSnapshotCreateValidSyntaxFromRepo(c *C) {
// Test that valid "from repo" syntax passes argument validation
args := []string{"valid-repo-snapshot", "from", "repo", "test-repo"}
// This will fail at repo loading but pass argument validation
err := aptlySnapshotCreate(s.cmd, args)
c.Check(err, NotNil)
@@ -117,18 +117,18 @@ func (s *SnapshotCreateSuite) TestSnapshotCreateMultipleEmpty(c *C) {
// Test creating multiple empty snapshots
emptySnapshots := []string{
"empty-snapshot-1",
"empty-snapshot-2",
"empty-snapshot-2",
"empty-snapshot-3",
}
for _, name := range emptySnapshots {
var buf bytes.Buffer
os.Stdout = &buf
args := []string{name, "empty"}
err := aptlySnapshotCreate(s.cmd, args)
c.Check(err, IsNil, Commentf("Failed for snapshot: %s", name))
output := buf.String()
c.Check(strings.Contains(output, "Snapshot "+name+" successfully created"), Equals, true,
Commentf("Output check failed for snapshot: %s", name))
@@ -144,15 +144,15 @@ func (s *SnapshotCreateSuite) TestSnapshotCreateSpecialCharacters(c *C) {
"snapshot123",
"UPPERCASESNAPSHOT",
}
for _, name := range testNames {
var buf bytes.Buffer
os.Stdout = &buf
args := []string{name, "empty"}
err := aptlySnapshotCreate(s.cmd, args)
c.Check(err, IsNil, Commentf("Failed for snapshot name: %s", name))
output := buf.String()
c.Check(strings.Contains(output, "Snapshot "+name+" successfully created"), Equals, true,
Commentf("Output check failed for snapshot name: %s", name))
@@ -162,13 +162,13 @@ func (s *SnapshotCreateSuite) TestSnapshotCreateSpecialCharacters(c *C) {
func (s *SnapshotCreateSuite) TestSnapshotCreateEmptyName(c *C) {
// Test creating snapshot with empty name
args := []string{"", "empty"}
var buf bytes.Buffer
os.Stdout = &buf
err := aptlySnapshotCreate(s.cmd, args)
c.Check(err, IsNil) // Empty name is technically valid
output := buf.String()
c.Check(strings.Contains(output, "successfully created"), Equals, true)
}
@@ -176,11 +176,11 @@ func (s *SnapshotCreateSuite) TestSnapshotCreateEmptyName(c *C) {
func (s *SnapshotCreateSuite) TestMakeCmdSnapshotCreate(c *C) {
// Test command creation and configuration
cmd := makeCmdSnapshotCreate()
c.Check(cmd.Run, NotNil)
c.Check(cmd.UsageLine, Equals, "create <name> (from mirror <mirror-name> | from repo <repo-name> | empty)")
c.Check(cmd.Short, Equals, "creates snapshot of mirror (local repository) contents")
// Test long description content
c.Check(strings.Contains(cmd.Long, "Command create <name> from mirror"), Equals, true)
c.Check(strings.Contains(cmd.Long, "Command create <name> from repo"), Equals, true)
@@ -191,7 +191,7 @@ func (s *SnapshotCreateSuite) TestMakeCmdSnapshotCreate(c *C) {
func (s *SnapshotCreateSuite) TestSnapshotCreateLongDescription(c *C) {
// Test detailed long description content
cmd := makeCmdSnapshotCreate()
c.Check(strings.Contains(cmd.Long, "persistent immutable snapshot"), Equals, true)
c.Check(strings.Contains(cmd.Long, "Snapshot could be published"), Equals, true)
c.Check(strings.Contains(cmd.Long, "merge, pull and other aptly features"), Equals, true)
@@ -202,14 +202,14 @@ func (s *SnapshotCreateSuite) TestSnapshotCreateLongDescription(c *C) {
func (s *SnapshotCreateSuite) TestSnapshotCreateArgumentCombinations(c *C) {
// Test various argument combination edge cases
// Valid combinations that should pass argument validation
validCombinations := [][]string{
{"test", "empty"},
{"test", "from", "mirror", "mirror-name"},
{"test", "from", "repo", "repo-name"},
}
for _, args := range validCombinations {
err := aptlySnapshotCreate(s.cmd, args)
// These should pass argument validation (not return commander.ErrCommandError)
@@ -218,19 +218,19 @@ func (s *SnapshotCreateSuite) TestSnapshotCreateArgumentCombinations(c *C) {
c.Fatalf("Argument validation failed for valid combination: %v", args)
}
}
// Invalid combinations that should fail argument validation
invalidCombinations := [][]string{
{}, // No arguments
{"test"}, // Missing type
{"test", "from"}, // Incomplete from
{"test", "from", "mirror"}, // Missing mirror name
{"test", "from", "repo"}, // Missing repo name
{}, // No arguments
{"test"}, // Missing type
{"test", "from"}, // Incomplete from
{"test", "from", "mirror"}, // Missing mirror name
{"test", "from", "repo"}, // Missing repo name
{"test", "from", "invalid", "source"}, // Invalid source type
{"test", "invalid"}, // Invalid type
{"test", "empty", "extra"}, // Extra arguments
{"test", "invalid"}, // Invalid type
{"test", "empty", "extra"}, // Extra arguments
}
for _, args := range invalidCombinations {
err := aptlySnapshotCreate(s.cmd, args)
c.Check(err, Equals, commander.ErrCommandError,
@@ -240,16 +240,16 @@ func (s *SnapshotCreateSuite) TestSnapshotCreateArgumentCombinations(c *C) {
func (s *SnapshotCreateSuite) TestSnapshotCreateCaseSensitivity(c *C) {
// Test that keywords are case sensitive
// These should fail because keywords must be exact
invalidCases := [][]string{
{"test", "Empty"}, // Capital E
{"test", "EMPTY"}, // All caps
{"test", "Empty"}, // Capital E
{"test", "EMPTY"}, // All caps
{"test", "from", "Mirror", "test"}, // Capital M
{"test", "from", "Repo", "test"}, // Capital R
{"test", "from", "Repo", "test"}, // Capital R
{"test", "From", "mirror", "test"}, // Capital F
}
for _, args := range invalidCases {
err := aptlySnapshotCreate(s.cmd, args)
c.Check(err, Equals, commander.ErrCommandError,
@@ -260,22 +260,22 @@ func (s *SnapshotCreateSuite) TestSnapshotCreateCaseSensitivity(c *C) {
func (s *SnapshotCreateSuite) TestSnapshotCreateOutputFormat(c *C) {
// Test the specific output format for empty snapshots
args := []string{"format-test", "empty"}
var buf bytes.Buffer
os.Stdout = &buf
err := aptlySnapshotCreate(s.cmd, args)
c.Check(err, IsNil)
output := buf.String()
lines := strings.Split(strings.TrimSpace(output), "\n")
// Should have exactly 2 lines of output
c.Check(len(lines), Equals, 2)
// First line should contain success message
c.Check(lines[0], Matches, "Snapshot format-test successfully created\\.")
// Second line should contain publish instruction
c.Check(lines[1], Matches, "You can run 'aptly publish snapshot format-test' to publish snapshot as Debian repository\\.")
}
}
+19 -17
View File
@@ -266,9 +266,11 @@ type MockSnapshotDiffContext struct {
testOnlyMatchingFiltering bool
}
func (m *MockSnapshotDiffContext) Flags() *flag.FlagSet { return m.flags }
func (m *MockSnapshotDiffContext) Progress() aptly.Progress { return m.progress }
func (m *MockSnapshotDiffContext) NewCollectionFactory() *deb.CollectionFactory { return m.collectionFactory }
func (m *MockSnapshotDiffContext) Flags() *flag.FlagSet { return m.flags }
func (m *MockSnapshotDiffContext) Progress() aptly.Progress { return m.progress }
func (m *MockSnapshotDiffContext) NewCollectionFactory() *deb.CollectionFactory {
return m.collectionFactory
}
type MockSnapshotDiffCollection struct {
shouldErrorByNameA bool
@@ -290,7 +292,7 @@ func (m *MockSnapshotDiffCollection) ByName(name string) (*deb.Snapshot, error)
Description: "Test snapshot",
}
snapshot.SetRefList(&MockSnapshotDiffRefList{name: name})
return snapshot, nil
}
@@ -331,7 +333,7 @@ func (m *MockSnapshotDiffRefList) Diff(other *deb.PackageRefList, packageCollect
})
} else if context, ok := context.(*MockSnapshotDiffContext); ok && context.testAllPackageStates {
// Include all types of changes
// Package only in B (addition)
diff = append(diff, &deb.PackageDiff{
Left: nil,
@@ -376,11 +378,11 @@ func (s *deb.Snapshot) SetRefList(refList *deb.PackageRefList) {
func (s *SnapshotDiffSuite) TestAptlySnapshotDiffScenarios(c *C) {
// Test scenarios for package differences
scenarios := []struct {
name string
testAllPackageStates bool
testOnlyMatching bool
identicalSnapshots bool
expectedMessages int
name string
testAllPackageStates bool
testOnlyMatching bool
identicalSnapshots bool
expectedMessages int
expectedColoredMessages int
}{
{"identical", false, false, true, 1, 0},
@@ -403,12 +405,12 @@ func (s *SnapshotDiffSuite) TestAptlySnapshotDiffScenarios(c *C) {
err := aptlySnapshotDiff(s.cmd, args)
c.Check(err, IsNil, Commentf("Scenario: %s", scenario.name))
c.Check(len(s.mockProgress.Messages) >= scenario.expectedMessages, Equals, true,
Commentf("Scenario: %s, expected at least %d messages, got %d",
c.Check(len(s.mockProgress.Messages) >= scenario.expectedMessages, Equals, true,
Commentf("Scenario: %s, expected at least %d messages, got %d",
scenario.name, scenario.expectedMessages, len(s.mockProgress.Messages)))
c.Check(len(s.mockProgress.ColoredMessages) >= scenario.expectedColoredMessages, Equals, true,
Commentf("Scenario: %s, expected at least %d colored messages, got %d",
Commentf("Scenario: %s, expected at least %d colored messages, got %d",
scenario.name, scenario.expectedColoredMessages, len(s.mockProgress.ColoredMessages)))
}
}
@@ -436,8 +438,8 @@ func (s *SnapshotDiffSuite) TestPackageDiffStructure(c *C) {
}{
{nil, &deb.Package{Name: "new", Version: "1.0", Architecture: "amd64"}, "addition"},
{&deb.Package{Name: "old", Version: "1.0", Architecture: "amd64"}, nil, "removal"},
{&deb.Package{Name: "pkg", Version: "1.0", Architecture: "amd64"},
&deb.Package{Name: "pkg", Version: "2.0", Architecture: "amd64"}, "update"},
{&deb.Package{Name: "pkg", Version: "1.0", Architecture: "amd64"},
&deb.Package{Name: "pkg", Version: "2.0", Architecture: "amd64"}, "update"},
}
for _, testCase := range testCases {
@@ -469,4 +471,4 @@ func (s *SnapshotDiffSuite) TestSnapshotDiffEdgeCases(c *C) {
}
}
c.Check(foundIdenticalMessage, Equals, true)
}
}
+14 -12
View File
@@ -39,9 +39,9 @@ func (s *SnapshotFilterSuite) SetUpTest(c *C) {
collectionFactory: s.collectionFactory,
architectures: []string{"amd64", "i386"},
dependencyOptions: aptly.DependencyOptions{
FollowRecommends: false,
FollowSuggests: false,
FollowSource: false,
FollowRecommends: false,
FollowSuggests: false,
FollowSource: false,
FollowAllVariants: false,
},
}
@@ -283,7 +283,7 @@ func (s *SnapshotFilterSuite) TestAptlySnapshotFilterArchitectureHandling(c *C)
for _, testCase := range testCases {
s.mockContext.architectures = testCase.contextArchs
args := []string{"source-snapshot", "dest-snapshot", "nginx"}
err := aptlySnapshotFilter(s.cmd, args)
c.Check(err, IsNil, Commentf("Context architectures: %v", testCase.contextArchs))
@@ -330,11 +330,13 @@ type MockSnapshotFilterContext struct {
dependencyOptions int
}
func (m *MockSnapshotFilterContext) Flags() *flag.FlagSet { return m.flags }
func (m *MockSnapshotFilterContext) Progress() aptly.Progress { return m.progress }
func (m *MockSnapshotFilterContext) NewCollectionFactory() *deb.CollectionFactory { return m.collectionFactory }
func (m *MockSnapshotFilterContext) ArchitecturesList() []string { return m.architectures }
func (m *MockSnapshotFilterContext) DependencyOptions() int { return m.dependencyOptions }
func (m *MockSnapshotFilterContext) Flags() *flag.FlagSet { return m.flags }
func (m *MockSnapshotFilterContext) Progress() aptly.Progress { return m.progress }
func (m *MockSnapshotFilterContext) NewCollectionFactory() *deb.CollectionFactory {
return m.collectionFactory
}
func (m *MockSnapshotFilterContext) ArchitecturesList() []string { return m.architectures }
func (m *MockSnapshotFilterContext) DependencyOptions() int { return m.dependencyOptions }
type MockSnapshotFilterCollection struct {
shouldErrorByName bool
@@ -352,7 +354,7 @@ func (m *MockSnapshotFilterCollection) ByName(name string) (*deb.Snapshot, error
Description: "Test snapshot",
}
snapshot.SetRefList(&MockSnapshotFilterRefList{})
return snapshot, nil
}
@@ -410,7 +412,7 @@ func (m *MockSnapshotFilterPackageList) Filter(options deb.FilterOptions) (*deb.
if m.collection != nil && m.collection.shouldErrorFilter {
return nil, fmt.Errorf("mock filter error")
}
// Return a filtered package list
return &MockSnapshotFilterPackageList{}, nil
}
@@ -504,4 +506,4 @@ func (s *SnapshotFilterSuite) TestAptlySnapshotFilterSnapshotCreation(c *C) {
expectedDesc := fmt.Sprintf("Filtered '%s', query was: '%s'", "test-source", "nginx")
c.Check(len(expectedDesc) > 0, Equals, true)
c.Check(strings.Contains(expectedDesc, "Filtered"), Equals, true)
}
}
+19 -17
View File
@@ -159,7 +159,7 @@ func (s *SnapshotListSuite) TestAptlySnapshotListJSON(c *C) {
outputStr := output.String()
c.Check(strings.Contains(outputStr, "{"), Equals, true)
c.Check(strings.Contains(outputStr, "}"), Equals, true)
// Verify it's valid JSON
var snapshots []interface{}
err = json.Unmarshal([]byte(strings.TrimSpace(outputStr)), &snapshots)
@@ -281,7 +281,7 @@ func (s *SnapshotListSuite) TestAptlySnapshotListJSONSorting(c *C) {
// Should complete successfully with sorted JSON output
outputStr := output.String()
c.Check(len(outputStr) > 0, Equals, true)
// Verify it's valid JSON
var snapshots []map[string]interface{}
err = json.Unmarshal([]byte(strings.TrimSpace(outputStr)), &snapshots)
@@ -306,16 +306,18 @@ type MockSnapshotListContext struct {
collectionFactory *deb.CollectionFactory
}
func (m *MockSnapshotListContext) Flags() *flag.FlagSet { return m.flags }
func (m *MockSnapshotListContext) Progress() aptly.Progress { return m.progress }
func (m *MockSnapshotListContext) NewCollectionFactory() *deb.CollectionFactory { return m.collectionFactory }
func (m *MockSnapshotListContext) Flags() *flag.FlagSet { return m.flags }
func (m *MockSnapshotListContext) Progress() aptly.Progress { return m.progress }
func (m *MockSnapshotListContext) NewCollectionFactory() *deb.CollectionFactory {
return m.collectionFactory
}
type MockSnapshotListCollection struct {
emptyCollection bool
shouldErrorForEach bool
causeMarshalError bool
multipleSnapshots bool
snapshotNames []string
emptyCollection bool
shouldErrorForEach bool
causeMarshalError bool
multipleSnapshots bool
snapshotNames []string
}
func (m *MockSnapshotListCollection) Len() int {
@@ -341,7 +343,7 @@ func (m *MockSnapshotListCollection) ForEachSorted(sortMethod string, handler fu
// Sort snapshots based on method
names := make([]string, len(m.snapshotNames))
copy(names, m.snapshotNames)
if sortMethod == "name" {
// Sort alphabetically for name sorting
for i := 0; i < len(names)-1; i++ {
@@ -359,7 +361,7 @@ func (m *MockSnapshotListCollection) ForEachSorted(sortMethod string, handler fu
Name: name,
Description: "Test snapshot",
}
if err := handler(snapshot); err != nil {
return err
}
@@ -369,13 +371,13 @@ func (m *MockSnapshotListCollection) ForEachSorted(sortMethod string, handler fu
Name: "test-snapshot",
Description: "Test snapshot",
}
// Create problematic snapshot for marshal error testing
if m.causeMarshalError {
// Create a cyclic structure that can't be marshaled
snapshot.TestCyclicRef = snapshot
}
return handler(snapshot)
}
@@ -468,7 +470,7 @@ func (s *SnapshotListSuite) TestFlagCombinations(c *C) {
s.cmd.Flag.Set(flag, "false")
}
}
fmt.Printf = originalPrintf
fmt.Println = originalPrintln
}
@@ -524,8 +526,8 @@ func (s *SnapshotListSuite) TestEdgeCases(c *C) {
// Test with snapshot that has minimal configuration
snapshot := &deb.Snapshot{Name: "simple-snapshot"}
c.Check(snapshot.Name, Equals, "simple-snapshot")
// Test string representation with minimal data
stringRep := snapshot.String()
c.Check(strings.Contains(stringRep, "simple-snapshot"), Equals, true)
}
}
+13 -11
View File
@@ -306,13 +306,13 @@ func (s *SnapshotMergeSuite) TestAptlySnapshotMergeFilterLatestRefs(c *C) {
func (s *SnapshotMergeSuite) TestAptlySnapshotMergeOverrideMatching(c *C) {
// Test override matching behavior with different flag combinations
scenarios := []struct {
latest bool
noRemove bool
latest bool
noRemove bool
expectOverride bool
}{
{false, false, true}, // Default: override matching
{true, false, false}, // Latest: no override matching
{false, true, false}, // No-remove: no override matching
{false, false, true}, // Default: override matching
{true, false, false}, // Latest: no override matching
{false, true, false}, // No-remove: no override matching
}
for _, scenario := range scenarios {
@@ -345,9 +345,11 @@ type MockSnapshotMergeContext struct {
collectionFactory *deb.CollectionFactory
}
func (m *MockSnapshotMergeContext) Flags() *flag.FlagSet { return m.flags }
func (m *MockSnapshotMergeContext) Progress() aptly.Progress { return m.progress }
func (m *MockSnapshotMergeContext) NewCollectionFactory() *deb.CollectionFactory { return m.collectionFactory }
func (m *MockSnapshotMergeContext) Flags() *flag.FlagSet { return m.flags }
func (m *MockSnapshotMergeContext) Progress() aptly.Progress { return m.progress }
func (m *MockSnapshotMergeContext) NewCollectionFactory() *deb.CollectionFactory {
return m.collectionFactory
}
type MockSnapshotMergeCollection struct {
shouldErrorByName bool
@@ -496,8 +498,8 @@ func (s *SnapshotMergeSuite) TestErrorMessageFormatting(c *C) {
func (s *SnapshotMergeSuite) TestMergeStrategyValidation(c *C) {
// Test different merge strategies
strategies := []struct {
latest bool
noRemove bool
latest bool
noRemove bool
expectedStrategy string
}{
{false, false, "override"},
@@ -535,4 +537,4 @@ func (s *SnapshotMergeSuite) TestDescriptionWithManySources(c *C) {
}
}
c.Check(foundSuccessMessage, Equals, true)
}
}
+21 -17
View File
@@ -226,7 +226,7 @@ func (s *SnapshotPullSuite) TestAptlySnapshotPullFilterError(c *C) {
func (s *SnapshotPullSuite) TestAptlySnapshotPullWithFlags(c *C) {
// Test pull with various flags
flagTests := []struct {
flag string
flag string
value string
}{
{"no-deps", "true"},
@@ -300,7 +300,7 @@ func (s *SnapshotPullSuite) TestAptlySnapshotPullArchitectureFiltering(c *C) {
func (s *SnapshotPullSuite) TestAptlySnapshotPullPackageProcessing(c *C) {
// Test package addition and removal logic
s.cmd.Flag.Set("no-remove", "false") // Allow removal
s.cmd.Flag.Set("no-remove", "false") // Allow removal
s.cmd.Flag.Set("all-matches", "false") // Only first match
args := []string{"target-snapshot", "source-snapshot", "dest-snapshot", "package-name"}
@@ -396,18 +396,20 @@ type MockSnapshotPullContext struct {
dependencyOptions int
}
func (m *MockSnapshotPullContext) Flags() *flag.FlagSet { return m.flags }
func (m *MockSnapshotPullContext) Progress() aptly.Progress { return m.progress }
func (m *MockSnapshotPullContext) NewCollectionFactory() *deb.CollectionFactory { return m.collectionFactory }
func (m *MockSnapshotPullContext) ArchitecturesList() []string { return m.architecturesList }
func (m *MockSnapshotPullContext) DependencyOptions() int { return m.dependencyOptions }
func (m *MockSnapshotPullContext) Flags() *flag.FlagSet { return m.flags }
func (m *MockSnapshotPullContext) Progress() aptly.Progress { return m.progress }
func (m *MockSnapshotPullContext) NewCollectionFactory() *deb.CollectionFactory {
return m.collectionFactory
}
func (m *MockSnapshotPullContext) ArchitecturesList() []string { return m.architecturesList }
func (m *MockSnapshotPullContext) DependencyOptions() int { return m.dependencyOptions }
type MockSnapshotPullCollection struct {
shouldErrorByName bool
shouldErrorLoadComplete bool
shouldErrorSourceByName bool
shouldErrorSourceLoadComplete bool
shouldErrorAdd bool
shouldErrorByName bool
shouldErrorLoadComplete bool
shouldErrorSourceByName bool
shouldErrorSourceLoadComplete bool
shouldErrorAdd bool
}
func (m *MockSnapshotPullCollection) ByName(name string) (*deb.Snapshot, error) {
@@ -516,7 +518,7 @@ func init() {
type MockSnapshotPullQuery struct{}
func (m *MockSnapshotPullQuery) Matches(pkg *deb.Package) bool { return true }
func (m *MockSnapshotPullQuery) String() string { return "mock-query" }
func (m *MockSnapshotPullQuery) String() string { return "mock-query" }
// Mock field query for architecture filtering
type MockFieldQuery struct {
@@ -526,7 +528,9 @@ type MockFieldQuery struct {
}
func (m *MockFieldQuery) Matches(pkg *deb.Package) bool { return true }
func (m *MockFieldQuery) String() string { return fmt.Sprintf("%s %s %s", m.Field, m.Relation, m.Value) }
func (m *MockFieldQuery) String() string {
return fmt.Sprintf("%s %s %s", m.Field, m.Relation, m.Value)
}
// Mock OR query
type MockOrQuery struct {
@@ -535,7 +539,7 @@ type MockOrQuery struct {
}
func (m *MockOrQuery) Matches(pkg *deb.Package) bool { return m.L.Matches(pkg) || m.R.Matches(pkg) }
func (m *MockOrQuery) String() string { return fmt.Sprintf("(%s | %s)", m.L.String(), m.R.String()) }
func (m *MockOrQuery) String() string { return fmt.Sprintf("(%s | %s)", m.L.String(), m.R.String()) }
// Mock AND query
type MockAndQuery struct {
@@ -544,7 +548,7 @@ type MockAndQuery struct {
}
func (m *MockAndQuery) Matches(pkg *deb.Package) bool { return m.L.Matches(pkg) && m.R.Matches(pkg) }
func (m *MockAndQuery) String() string { return fmt.Sprintf("(%s, %s)", m.L.String(), m.R.String()) }
func (m *MockAndQuery) String() string { return fmt.Sprintf("(%s, %s)", m.L.String(), m.R.String()) }
// Mock dependency struct
type MockDependency struct {
@@ -555,4 +559,4 @@ type MockDependency struct {
// Mock package struct methods
func (p *deb.Package) String() string {
return fmt.Sprintf("%s_%s", p.Name, p.Architecture)
}
}
+23 -21
View File
@@ -370,17 +370,19 @@ type MockSnapshotSearchContext struct {
dependencyOptions int
}
func (m *MockSnapshotSearchContext) Flags() *flag.FlagSet { return m.flags }
func (m *MockSnapshotSearchContext) Progress() aptly.Progress { return m.progress }
func (m *MockSnapshotSearchContext) NewCollectionFactory() *deb.CollectionFactory { return m.collectionFactory }
func (m *MockSnapshotSearchContext) ArchitecturesList() []string { return m.architecturesList }
func (m *MockSnapshotSearchContext) DependencyOptions() int { return m.dependencyOptions }
func (m *MockSnapshotSearchContext) Flags() *flag.FlagSet { return m.flags }
func (m *MockSnapshotSearchContext) Progress() aptly.Progress { return m.progress }
func (m *MockSnapshotSearchContext) NewCollectionFactory() *deb.CollectionFactory {
return m.collectionFactory
}
func (m *MockSnapshotSearchContext) ArchitecturesList() []string { return m.architecturesList }
func (m *MockSnapshotSearchContext) DependencyOptions() int { return m.dependencyOptions }
type MockSnapshotSearchCollection struct {
shouldErrorByName bool
shouldErrorLoadComplete bool
byNameCalled bool
loadCompleteCalled bool
shouldErrorByName bool
shouldErrorLoadComplete bool
byNameCalled bool
loadCompleteCalled bool
}
func (m *MockSnapshotSearchCollection) ByName(name string) (*deb.Snapshot, error) {
@@ -403,10 +405,10 @@ func (m *MockSnapshotSearchCollection) LoadComplete(snapshot *deb.Snapshot) erro
}
type MockRemoteSearchRepoCollection struct {
shouldErrorByName bool
shouldErrorLoadComplete bool
byNameCalled bool
loadCompleteCalled bool
shouldErrorByName bool
shouldErrorLoadComplete bool
byNameCalled bool
loadCompleteCalled bool
}
func (m *MockRemoteSearchRepoCollection) ByName(name string) (*deb.RemoteRepo, error) {
@@ -429,10 +431,10 @@ func (m *MockRemoteSearchRepoCollection) LoadComplete(repo *deb.RemoteRepo) erro
}
type MockLocalSearchRepoCollection struct {
shouldErrorByName bool
shouldErrorLoadComplete bool
byNameCalled bool
loadCompleteCalled bool
shouldErrorByName bool
shouldErrorLoadComplete bool
byNameCalled bool
loadCompleteCalled bool
}
func (m *MockLocalSearchRepoCollection) ByName(name string) (*deb.LocalRepo, error) {
@@ -487,7 +489,7 @@ func NewPackageListFromRefListSearch(refList *deb.PackageRefList, packageCollect
if collection, ok := packageCollection.(*MockPackageSearchCollection); ok && collection.shouldErrorFilter {
return nil, fmt.Errorf("mock filter error")
}
resultList := &deb.PackageList{}
if collection, ok := packageCollection.(*MockPackageSearchCollection); ok && collection.emptyResults {
resultList.Len = func() int { return 0 }
@@ -517,7 +519,7 @@ func (r *deb.LocalRepo) RefList() *deb.PackageRefList {
type MockMatchAllQuery struct{}
func (m *MockMatchAllQuery) Matches(pkg *deb.Package) bool { return true }
func (m *MockMatchAllQuery) String() string { return "*" }
func (m *MockMatchAllQuery) String() string { return "*" }
// Override deb.MatchAllQuery for testing
func init() {
@@ -548,6 +550,6 @@ func init() {
type MockSearchQuery struct{}
func (m *MockSearchQuery) Matches(pkg *deb.Package) bool { return true }
func (m *MockSearchQuery) String() string { return "mock-search-query" }
func (m *MockSearchQuery) String() string { return "mock-search-query" }
// GetStringOrFileContent function is already defined in string_or_file_flag.go
// GetStringOrFileContent function is already defined in string_or_file_flag.go
+20 -18
View File
@@ -253,8 +253,8 @@ func (s *SnapshotShowSuite) TestAptlySnapshotShowJSONRemoteRepoSources(c *C) {
func (s *SnapshotShowSuite) TestAptlySnapshotShowSourceErrors(c *C) {
// Test handling of source lookup errors (should continue gracefully)
mockSnapshotCollection := &MockSnapshotShowCollection{
hasSnapshotSources: true,
shouldErrorByUUID: true,
hasSnapshotSources: true,
shouldErrorByUUID: true,
}
s.collectionFactory.snapshotCollection = mockSnapshotCollection
@@ -269,7 +269,7 @@ func (s *SnapshotShowSuite) TestAptlySnapshotShowSourceErrors(c *C) {
func (s *SnapshotShowSuite) TestAptlySnapshotShowJSONMarshalError(c *C) {
// Test JSON marshal error handling
s.cmd.Flag.Set("json", "true")
// Create a snapshot that will cause JSON marshal error
mockCollection := &MockSnapshotShowCollection{causeMarshalError: true}
s.collectionFactory.snapshotCollection = mockCollection
@@ -323,22 +323,24 @@ type MockSnapshotShowContext struct {
collectionFactory *deb.CollectionFactory
}
func (m *MockSnapshotShowContext) Flags() *flag.FlagSet { return m.flags }
func (m *MockSnapshotShowContext) Progress() aptly.Progress { return m.progress }
func (m *MockSnapshotShowContext) NewCollectionFactory() *deb.CollectionFactory { return m.collectionFactory }
func (m *MockSnapshotShowContext) Flags() *flag.FlagSet { return m.flags }
func (m *MockSnapshotShowContext) Progress() aptly.Progress { return m.progress }
func (m *MockSnapshotShowContext) NewCollectionFactory() *deb.CollectionFactory {
return m.collectionFactory
}
type MockSnapshotShowCollection struct {
shouldErrorByName bool
shouldErrorLoadComplete bool
shouldErrorByUUID bool
hasSnapshotSources bool
hasLocalRepoSources bool
hasRemoteRepoSources bool
causeMarshalError bool
emptyRefList bool
byNameCalled bool
loadCompleteCalled bool
byUUIDCalled bool
shouldErrorByName bool
shouldErrorLoadComplete bool
shouldErrorByUUID bool
hasSnapshotSources bool
hasLocalRepoSources bool
hasRemoteRepoSources bool
causeMarshalError bool
emptyRefList bool
byNameCalled bool
loadCompleteCalled bool
byUUIDCalled bool
}
func (m *MockSnapshotShowCollection) ByName(name string) (*deb.Snapshot, error) {
@@ -491,4 +493,4 @@ func (s *SnapshotShowSuite) SetUpSuite(c *C) {
// Redirect stdout to capture output for testing
originalStdout := os.Stdout
_ = originalStdout // Prevent unused variable warning
}
}
+20 -18
View File
@@ -202,7 +202,7 @@ func (s *SnapshotVerifySuite) TestAptlySnapshotVerifyArchitectureHandling(c *C)
for _, testCase := range testCases {
s.mockContext.architectures = testCase.contextArchs
args := []string{"test-snapshot"}
err := aptlySnapshotVerify(s.cmd, args)
c.Check(err, IsNil, Commentf("Context architectures: %v", testCase.contextArchs))
@@ -270,11 +270,13 @@ type MockSnapshotVerifyContext struct {
dependencyOptions int
}
func (m *MockSnapshotVerifyContext) Flags() *flag.FlagSet { return m.flags }
func (m *MockSnapshotVerifyContext) Progress() aptly.Progress { return m.progress }
func (m *MockSnapshotVerifyContext) NewCollectionFactory() *deb.CollectionFactory { return m.collectionFactory }
func (m *MockSnapshotVerifyContext) ArchitecturesList() []string { return m.architectures }
func (m *MockSnapshotVerifyContext) DependencyOptions() int { return m.dependencyOptions }
func (m *MockSnapshotVerifyContext) Flags() *flag.FlagSet { return m.flags }
func (m *MockSnapshotVerifyContext) Progress() aptly.Progress { return m.progress }
func (m *MockSnapshotVerifyContext) NewCollectionFactory() *deb.CollectionFactory {
return m.collectionFactory
}
func (m *MockSnapshotVerifyContext) ArchitecturesList() []string { return m.architectures }
func (m *MockSnapshotVerifyContext) DependencyOptions() int { return m.dependencyOptions }
type MockSnapshotVerifyCollection struct {
shouldErrorByName bool
@@ -291,7 +293,7 @@ func (m *MockSnapshotVerifyCollection) ByName(name string) (*deb.Snapshot, error
Description: "Test snapshot",
}
snapshot.SetRefList(&MockSnapshotVerifyRefList{})
return snapshot, nil
}
@@ -319,7 +321,7 @@ type MockSnapshotVerifyPackageCollection struct {
func (m *MockSnapshotVerifyPackageCollection) NewPackageListFromRefList(refList *deb.PackageRefList, progress aptly.Progress) (*deb.PackageList, error) {
m.callCount++
if m.shouldErrorNewPackageList && m.callCount == 1 {
return nil, fmt.Errorf("mock new package list error")
}
@@ -328,11 +330,11 @@ func (m *MockSnapshotVerifyPackageCollection) NewPackageListFromRefList(refList
}
packageList := &MockSnapshotVerifyPackageList{
collection: m,
emptyArchitectures: m.emptyArchitectures,
hasMissingDependencies: m.hasMissingDependencies,
collection: m,
emptyArchitectures: m.emptyArchitectures,
hasMissingDependencies: m.hasMissingDependencies,
shouldErrorVerifyDependencies: m.shouldErrorVerifyDependencies,
isFirstCall: m.callCount == 1,
isFirstCall: m.callCount == 1,
}
return packageList, nil
}
@@ -371,7 +373,7 @@ func (m *MockSnapshotVerifyPackageList) VerifyDependencies(options int, architec
if m.shouldErrorVerifyDependencies {
return nil, fmt.Errorf("mock verify dependencies error")
}
if m.hasMissingDependencies {
// Return some mock missing dependencies
missing := []*deb.Dependency{
@@ -380,7 +382,7 @@ func (m *MockSnapshotVerifyPackageList) VerifyDependencies(options int, architec
}
return missing, nil
}
// No missing dependencies
return []*deb.Dependency{}, nil
}
@@ -419,7 +421,7 @@ func (s *SnapshotVerifySuite) TestDependencySorting(c *C) {
// Test that missing dependencies are sorted correctly
deps := []string{"z-package", "a-package", "m-package"}
sort.Strings(deps)
expected := []string{"a-package", "m-package", "z-package"}
c.Check(deps, DeepEquals, expected)
}
@@ -435,7 +437,7 @@ func (s *SnapshotVerifySuite) TestArchitectureCombinations(c *C) {
for _, archs := range testArchs {
s.mockContext.architectures = archs
args := []string{"test-snapshot"}
err := aptlySnapshotVerify(s.cmd, args)
c.Check(err, IsNil, Commentf("Architectures: %v", archs))
@@ -476,7 +478,7 @@ func (s *SnapshotVerifySuite) TestDependencyOptionsCombinations(c *C) {
for _, options := range optionTests {
s.mockContext.dependencyOptions = options
args := []string{"test-snapshot"}
err := aptlySnapshotVerify(s.cmd, args)
c.Check(err, IsNil, Commentf("Options: %+v", options))
@@ -508,4 +510,4 @@ func (s *SnapshotVerifySuite) TestMultipleMissingDependenciesDisplay(c *C) {
}
c.Check(foundMissingCount, Equals, true)
c.Check(foundDependencyList, Equals, true)
}
}
+8 -8
View File
@@ -15,10 +15,10 @@ import (
)
type TaskRunSuite struct {
cmd *commander.Command
mockProgress *MockTaskRunProgress
mockContext *MockTaskRunContext
tempFile *os.File
cmd *commander.Command
mockProgress *MockTaskRunProgress
mockContext *MockTaskRunContext
tempFile *os.File
}
var _ = Suite(&TaskRunSuite{})
@@ -360,13 +360,13 @@ func (m *MockTaskRunProgress) Flush() {
}
type MockTaskRunContext struct {
flags *flag.FlagSet
progress *MockTaskRunProgress
flags *flag.FlagSet
progress *MockTaskRunProgress
shouldErrorReOpenDB bool
shouldErrorRun bool
}
func (m *MockTaskRunContext) Flags() *flag.FlagSet { return m.flags }
func (m *MockTaskRunContext) Flags() *flag.FlagSet { return m.flags }
func (m *MockTaskRunContext) Progress() aptly.Progress { return m.progress }
func (m *MockTaskRunContext) ReOpenDatabase() error {
@@ -455,4 +455,4 @@ func (s *TaskRunSuite) TestAptlyTaskRunScannerError(c *C) {
// Should succeed with /dev/null but have no commands
c.Check(err, NotNil)
c.Check(err.Error(), Matches, ".*the file is empty.*")
}
}