@Test public void testFindImagesAndFix_notModifiedPostData() throws Exception { gitHubUtil = mock(GitHubUtil.class); BufferedReader reader = mock(BufferedReader.class); GHContent content = mock(GHContent.class); when(content.getPath()).thenReturn("path"); when(content.update(anyString(), anyString(), anyString())).thenReturn(null); when(reader.readLine()).thenReturn("hello", "FROM image:tag as builder", "this is a test", null); dockerfileGitHubUtil = new DockerfileGitHubUtil(gitHubUtil); StringBuilder strB = new StringBuilder(); boolean modified = dockerfileGitHubUtil.rewriteDockerfile("image", "tag", reader, strB); assertFalse(modified, "Expected the dockerfile to not have changed."); }
protected boolean rewriteDockerfile(String img, String tag, BufferedReader reader, StringBuilder strB) throws IOException { String line; boolean modified = false; while ( (line = reader.readLine()) != null ) { modified = changeIfDockerfileBaseImageLine(img, tag, strB, line) || modified; } return modified; }
DockerfileGitHubUtil { protected boolean rewriteDockerfile(String img, String tag, BufferedReader reader, StringBuilder strB) throws IOException { String line; boolean modified = false; while ( (line = reader.readLine()) != null ) { modified = changeIfDockerfileBaseImageLine(img, tag, strB, line) || modified; } return modified; } }
DockerfileGitHubUtil { protected boolean rewriteDockerfile(String img, String tag, BufferedReader reader, StringBuilder strB) throws IOException { String line; boolean modified = false; while ( (line = reader.readLine()) != null ) { modified = changeIfDockerfileBaseImageLine(img, tag, strB, line) || modified; } return modified; } DockerfileGitHubUtil(GitHubUtil gitHubUtil); }
DockerfileGitHubUtil { protected boolean rewriteDockerfile(String img, String tag, BufferedReader reader, StringBuilder strB) throws IOException { String line; boolean modified = false; while ( (line = reader.readLine()) != null ) { modified = changeIfDockerfileBaseImageLine(img, tag, strB, line) || modified; } return modified; } DockerfileGitHubUtil(GitHubUtil gitHubUtil); GHRepository getOrCreateFork(GHRepository parent); GHMyself getMyself(); GHRepository getRepo(String repoName); PagedSearchIterable<GHContent> findFilesWithImage(String query, String org); List<GHRepository> getGHRepositories(Multimap<String, String> pathToDockerfileInParentRepo,
                                                            GHMyself currentUser); void modifyAllOnGithub(GHRepository repo, String branch,
                                  String img, String tag); GHContent tryRetrievingContent(GHRepository repo, String path, String branch); void modifyOnGithub(GHContent content,
                               String branch, String img, String tag, String customMessage); GitHubJsonStore getGitHubJsonStore(String store); void createPullReq(GHRepository origRepo,
                              String branch, GHRepository forkRepo,
                              PullRequestInfo pullRequestInfo); Optional<GHPullRequest> getPullRequestForImageBranch(GHRepository repository, GitForkBranch gitForkBranch); void createOrUpdateForkBranchToParentDefault(GHRepository parent, GHRepository fork, GitForkBranch gitForkBranch); boolean thisUserIsOwner(GHRepository repo); Optional<PagedSearchIterable<GHContent>> getGHContents(String org, String img); }
DockerfileGitHubUtil { protected boolean rewriteDockerfile(String img, String tag, BufferedReader reader, StringBuilder strB) throws IOException { String line; boolean modified = false; while ( (line = reader.readLine()) != null ) { modified = changeIfDockerfileBaseImageLine(img, tag, strB, line) || modified; } return modified; } DockerfileGitHubUtil(GitHubUtil gitHubUtil); GHRepository getOrCreateFork(GHRepository parent); GHMyself getMyself(); GHRepository getRepo(String repoName); PagedSearchIterable<GHContent> findFilesWithImage(String query, String org); List<GHRepository> getGHRepositories(Multimap<String, String> pathToDockerfileInParentRepo,
                                                            GHMyself currentUser); void modifyAllOnGithub(GHRepository repo, String branch,
                                  String img, String tag); GHContent tryRetrievingContent(GHRepository repo, String path, String branch); void modifyOnGithub(GHContent content,
                               String branch, String img, String tag, String customMessage); GitHubJsonStore getGitHubJsonStore(String store); void createPullReq(GHRepository origRepo,
                              String branch, GHRepository forkRepo,
                              PullRequestInfo pullRequestInfo); Optional<GHPullRequest> getPullRequestForImageBranch(GHRepository repository, GitForkBranch gitForkBranch); void createOrUpdateForkBranchToParentDefault(GHRepository parent, GHRepository fork, GitForkBranch gitForkBranch); boolean thisUserIsOwner(GHRepository repo); Optional<PagedSearchIterable<GHContent>> getGHContents(String org, String img);  }