Skip to content

Instantly share code, notes, and snippets.

@ad3n
Created June 29, 2022 04:51
Show Gist options
  • Save ad3n/277cdf2c7472c565b6706f25f74ce11d to your computer and use it in GitHub Desktop.
Save ad3n/277cdf2c7472c565b6706f25f74ce11d to your computer and use it in GitHub Desktop.

Saya punya interface dengan spek sebagai berikut:

type BookRepository interface {
    Save(model *models.Book) error
}

saya punya service dengan spek sebagai berikut:

type Service struct{
    repository repositories.BookRepository
}

func (s *Service) Save(model *models.Book) error {
    err := s.repository.Save(model)
    if err == tools.ErrorAlreadyExists {
        return errors.New("Title already exists")
    }

    if err == tools.ErrorStorage {
        return errors.New("Internal error")
    }

    return err
}

buat program untuk mensimulasikan skenario di atas (dapat dijalankan dengan go run main.go) dan buatlah unit test untuk kasus di atas

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment